C language programming The twenty-eighth week The design of multifunctional hexadecimal converter

C language programming The twenty-eighth week The design of multifunctional hexadecimal converter

Design of multi-function hexadecimal converter

In the past two days, I have written a multi-functional hexadecimal converter in C language, which can realize the conversion of decimal number to binary number, the conversion of decimal number to octal number, the conversion of decimal number to hexadecimal number, and the conversion of binary number to octal Number conversion, binary number to decimal number conversion, binary number to hexadecimal number conversion, and arbitrary base number to decimal number conversion and decimal number to arbitrary base number conversion. It basically covers all the hexadecimal conversion types that programmers use in their daily designs. The color of the running window is aqua blue which is more eye-friendly and beautiful. Not much nonsense, just go to the code.

code show as below:

# include <stdio.h> # include <stdlib.h> # include <windows.h> void ten_two () ;//decimal binary void ten_eight () ;//decimal octal void ten_sixteen () ;//decimal hexadecimal void two_eight () ;//binary octal void two_ten () ;//Binary Decimal void two_sixteen () ;//Binary Hexadecimal void at_will_ten () ;//Arbitrary base Decimal void ten_at_will () ;//Decimal Arbitrary base void STarting_up () ; int main () { STarting_up(); } void STarting_up () { system( "cls" ); int n; do { system( "color B1" ); printf ( "\t\t\t\t\t ***************************** *****/n" ); printf ( "\t\t\t\t\t * * */n" ); printf ( "\t\t\t\t\t * welcome* multifunctional*/n" ); printf ( "\t\t\t\t\t * Use * Base Converter*/n" ); printf ( "\t\t\t\t\t * * */n" ); printf ( "\t\t\t\t\t **********************************/n\n" ); printf ( "\t\t\t\t\t @Enter 0 in each hexadecimal conversion function to return to this interface\n\n" ); printf ( "\t1. Decimal Binary\n\n" ); printf ( "\t2. Decimal Octal\n\n" ); printf ( "\t3. Decimal Hexadecimal\n\n" ) ; printf ( "\t4. Binary Octal\n\n" ); printf ( "\t5. Binary Decimal\n\n" ); printf ( "\t6. Binary Hexadecimal\n\n" ); printf ( "\t7. Arbitrary base Decimal\n\n" ); printf ( "\t8. Decimal Arbitrary base\n\n" ); printf ( "Please select function:" ); scanf ( "%d" ,&n); if (n== 0) break ; switch (n) { case 1 :ten_two(); break ; case 2 :ten_eight(); break ; case 3 :ten_sixteen(); break ; case 4 :two_eight(); break ; case 5 :two_ten(); break ; case 6 :two_sixteen( ); break ; case 7 :at_will_ten(); break ; case 8 :ten_at_will(); break ; default : printf ("The input is wrong, please choose between 1-8\n" ); } } while ( 1 ); } void ten_two () { system( "cls" ); printf ( "\t\t\t\t\t ****************************** *****/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t * decimal binary converter */n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t ************ ***********************\n\n" ); while ( 1 ) { int num, p[ 100 ],i=0 ,count; printf ( "Please enter a decimal number:" ); scanf ( "%d" ,&num); if (num== 0 ) STarting_up(); for (count = 0 ;;count++) { if (num== 0 ) break ; p[count]=num% 2 ; num=num/2 ; i++; } printf ( "Convert to binary:" ); for (count=i -1 ;count>= 0 ;count--) printf ( "%d" ,p[count]); printf ( "\n" ); } } void ten_eight () { system( "cls" ); printf ( "\t\t\t\t\t ****************************** *****/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t * decimal octal converter */n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t ************ ***********************\n\n" ); while ( 1 ) { int num, p[ 100 ],i= 0 ,count; printf ( "Please enter a decimal number:" ); scanf ( "%d" ,&num); if (num== 0 ) STarting_up(); for (count = 0 ;;count++) { if (num== 0 ) break ; p[count]=num%8 ; num=num/8 ; i++; } printf ( "Convert to octal:" ); for (count=i -1 ;count>= 0 ;count--) printf ( "%d" ,p[count]); printf ( "\n" ); } } void ten_sixteen () { system( "cls" ); printf ( "\t\t\t\t\t ****************************** *****/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t * decimal hexadecimal Converter*/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t ********* **************************\n\n" ); while ( 1 ) { int num, p[ 100 ],i= 0 ,count; printf ( "Please enter a decimal number:" ); scanf ( "%d" ,&num); if (num== 0 ) STarting_up(); for (count = 0 ;;count++) { if (num== 0 ) break ; p[count]=num% 16 ; num=num/16 ; i++; switch (p[count]) { case 10 :p[count]= 'A' ; break ; case 11 :p[count]= 'B' ; break ; case 12 :p[count]= 'C' ; break ; case 13 :p[count]= 'D' ; break ; case 14 :p[count]= 'E' ; break ; case 15 :p[count]= 'F' ; break ; } } printf ( "Convert to hexadecimal:" ); for (count=i -1 ;count>= 0 ;count--) { if (p[count]< 10 ) printf ( "%d" ,p[count]); if (p[count]>= 10 ) printf ( "%c" ,p[count]); } printf ( "\n" ); } } void two_eight () { system( "cls" ); printf ( "\t\t\t\t\t ****************************** *****/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t * binary octal converter */n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t ************ ***********************\n\n" ); while ( 1 ) { int x; printf ( "Please enter a binary number:" ); scanf ( "%d" ,&x); if (x== 0 ) STarting_up(); int y = 0 ,product = 1 ; while (x!= 0 ){ y=y+(x% 10 )*product; x=x/10 ; product=product* 2 ; } int num, p[ 100 ],i= 0 ,count; num=y; for (count = 0 ;;count++) { if (num== 0 ) break ; p[count]=num% 8 ; num=num/8 ; i++; } printf ( "Convert to octal:" ); for (count=i -1 ;count>= 0 ;count--) printf ( "%d" ,p[count]); printf ( "\n" ); } } void two_ten () { system( "cls" ); printf ( "\t\t\t\t\t ****************************** *****/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t * binary decimal converter */n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t ************ ***********************\n\n" ); while ( 1 ) { int x; printf ( "Please enter a binary number:" ); scanf ( "%d" ,&x); if (x== 0 ) STarting_up(); int y = 0 ,product = 1 ; while (x!= 0 ){ y=y+(x% 10 )*product; x=x/10 ; product=product* 2 ; } printf ( "Convert to decimal: %d\n" ,y); } } void two_sixteen () { system( "cls" ); printf ( "\t\t\t\t\t ****************************** *****/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t * binary hexadecimal Converter*/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t\t ********* **************************\n\n" ); while ( 1 ) { int x; printf ( "Please enter a binary number:" ); scanf ( "%d" ,&x); if (x== 0 ) STarting_up(); int y = 0 ,product = 1 ; while (x!= 0 ){ y=y+(x% 10 )*product; x=x/10 ; product=product* 2 ; } int num, p[ 100 ],i= 0 ,count; num=y; for (count = 0 ;;count++) { if (num== 0 ) break ; p[count]=num% 16 ; num=num/16 ; i++; switch (p[count]) { case 10 :p[count]= 'A' ; break ; case 11 :p[count]= 'B' ; break ; case 12 :p[count]= 'C' ; break ; case 13 :p[count]= 'D' ; break ; case 14 :p[count]= 'E' ; break ; case 15 :p[count]= 'F' ; break ; } } printf ( "Convert to hexadecimal:" ); for (count=i -1 ;count>= 0 ;count--) { if (p[count]< 10 ) printf ( "%d" ,p[count]); if (p[count]>= 10 ) printf ( "%c" ,p[count]); } printf ( "\n" ); } } void at_will_ten () {//Any hexadecimal to decimal system( "cls" ); printf ( "\t\t\t\t\t ****************** *****************/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t/t\t\t * arbitrary base decimal converter*/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t/t ***********************************\n\n" ); while ( 1 ) { int x,p; //x input number p the hexadecimal number of the number printf ( "Please input any number:" ); scanf ( "%d" ,&x); if (x== 0 ) STarting_up(); printf ( "Please describe the hexadecimal number of the number:" ); scanf ( "%d" ,&p); if (x== 0 ) STarting_up(); int y = 0 ,product = 1 ; while (x!= 0 ){ y=y+(x% 10 )*product; x=x/10 ; product=product*p; } printf ( "The converted decimal number is: %d\n" ,y); } } void ten_at_will () {//Decimal to arbitrary system system( "cls" ); printf ( "\t\t\t\t\t ****************** *****************/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t/t\t\t * Decimal Arbitrary Converter*/n" ); printf ( "\t\t\t\t\t * */n" ); printf ( "\t\t\t\t/t ***********************************\n\n" ); while ( 1 ) { int x,p; //x is a decimal number, p is the target hexadecimal size printf ( "Please enter any number:" ); scanf ( "%d" ,&x); if (x== 0 ) STarting_up(); printf ( "Please describe the hexadecimal number that needs to be converted into:" ); scanf ( "%d" ,&p); if (x== 0 ) STarting_up(); int a[ 100 ]; //store the remainder int count = 0 ; do { a[count++]=x%p; x=x/p; } while (x!= 0 ); //Loop when the quotient is not 0 for ( int i=count -1 ;i>= 0 ;i--){ printf ( "%d" ,a[i]) ; } printf ( "\n" ); } } Copy code

Boot main page:

Decimal number Binary number converter page

Decimal Number Octal Number Converter Page

Decimal Number Hexadecimal Number Converter Page

Binary Number Octal Number Converter Page

Binary Number Decimal Number Converter Page

Binary Number Hexadecimal Number Converter Page

Arbitrary number Decimal number converter page

Decimal number Arbitrary number converter page

The harder, the more fortunate!

Come on, Aoli give it! ! !