Complete and upload C program that will accomplish the following: Accept a numbe
ID: 3735809 • Letter: C
Question
Complete and upload C program that will accomplish the following:
Accept a number in binary or hexadecimal (hex numbers should start with 0x; binary number will be entered without designator) All numbers not entered with 0x designator will be considered as binary for this program. Convert the binary to hexadecimal (if binary number is entered) Convert the number to binary (if a hexadecimal number is entered) Allow user to continue entering numbers until a "exit" is requested. Upload a text file containing the C code that you successfully compiled and executed to meet the assignment objectives. Click on the title above to submit the assignment. Attached the file to upload.
Explanation / Answer
Solution:
binary to hexa converter code in C is given below:
code:
#include <stdio.h>
int main()
{
long int binaryval, hexadecimalval = 0, i = 1, remainder;
printf("Enter the binary number: ");
scanf("%ld", &binaryval);
while (binaryval != 0)
{
remainder = binaryval % 10;
hexadecimalval = hexadecimalval + remainder * i;
i = i * 2;
binaryval = binaryval / 10;
}
printf("Equivalent hexadecimal value: %lX", hexadecimalval);
return 0;
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.