Question: Draw a flowchart of this C program that reads an integer in Hexadecimal (base 16) entered by the user and displays it in octal (base

 Draw a flowchart of this C program that reads an integer

Draw a flowchart of this C program that reads an integer in Hexadecimal (base 16) entered by the user and displays it in octal (base 8):

in Hexadecimal (base 16) entered by the user and displays it in

octal (base 8): // C program to convert // Hexadecimal to Octal

#include #include #include // Function to convert Hexadecimal to Binary long long

// C program to convert // Hexadecimal to Octal #include #include #include // Function to convert Hexadecimal to Binary long long int hex_to_bin(char hex() { long long int bin, place; int i = 0, rem, val; bin = Oll; place = 011; // Hexadecimal to binary conversion for (i = 0; hex[i] != '\0'; i++) { bin = bin * place; - * switch (hex[i]) { case 'O': bin += 0; break; case '1': bin += 1; break; case '2': bin += 10; break; case '3': bin += 11; break; case '4': bin += 100; break; case '5': bin += 101; break; case '6': bin += 110; break; case '7': bin += 111; break; case '8': bin += 1000; break: case '9': bin += 1001; break; case 'a': case 'A': bin += 1010; break; case 'b': case 'B': bin += 1011; break; case 'c': case 'C': bin += 1100; break; case 'd': case 'D': bin += 1101; break; case 'e': case 'E': bin += 1110; break; case 'f': case 'Fl: bin += 1111; break; default: printf("Invalid hexadecimal input."); } place = 10000; = } return bin; } // Function to convert Binary to Octal long long int bin_to_oct(long long bin) { long long int octal, place; int i = 0, rem, val; = octal = Oll; place = Oll; place = 1; // Binary to octal conversion while (bin > 0) { rem = bin % 1000; - switch (rem) { case 0: val = 0; break; case 1: val = 1; break; case 10: val = 2; break; case 11: val = 3; break; case 100: val = 4; break; case 101: val = 5; break; case 110: val = 6; break; case 111: val = 7; break; } = * = octal = (val * place) + octal; bin /= 1000; place *= 10; } return octal; } // Function to Convert // Hexadecimal Number to Octal Number long long int hex_to_oct(char hexl) { long long int octal, bin; // convert HexaDecimal to Binary bin = hex_to_bin(hex); val = 6; break; case 111: val = 7; break; } = octal = (val * place) + octal; bin /= 1000; place *= 10; } return octal; } // Function to Convert // Hexadecimal Number to Octal Number long long int hex_to_oct(char hex[]) { long long int octal, bin; // convert Hexadecimal to Binary bin = hex_to_bin(hex); // convert Binary to Octal octal = bin_to_oct(bin); return octal; } // driver code int main() { // Get the hexadecimal number char hex[20] = "1F"; // convert hexadecimal to octal printf("Equivalent Octal Value = %lld", hex_to_oct(hex)); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!