current position:Home>C language hexadecimal conversion to decimal and octal

C language hexadecimal conversion to decimal and octal

2022-02-03 02:18:35 CSDN Q & A

perform printf("\x4a"); The output after is J
I want to know how it is transformed , Need to be very detailed
\ddd ddd:1-3 In octal form ASCII The character represented by the code
\dhh hh:1-2 In hexadecimal form .ASCII The character represented by the code




Refer to the answer 1:
// Hexadecimal to decimal , Binary system , octal .void X_D(char a[],int k){    int i, j, s = 0;    int result = 0;    int b[50];    for (i = 0; i < k; i++)    {        if(a[i] <= '9' && a[i] >= '1')            b[i]=a[i]-48;        else        {            switch(a[i])            {            case 'A': b[i] = 10;                break;            case 'B': b[i] = 11;                break;            case 'C': b[i] = 12;                break;            case 'D': b[i] = 13;                break;            case 'E': b[i] = 14;                break;            case 'F': b[i] = 15;                break;            case 'a': b[i] = 10;                break;            case 'b': b[i] = 11;                break;            case 'c': b[i] = 12;                break;            case 'd': b[i] = 13;                break;            case 'e': b[i] = 14;               break;            case 'f': b[i] = 15;               break;           default:                  s = 1;           }        }    }    for (i = 1, j = k - 1; j >= 0; j--, i *=16)        result+=b[j]*i;    if(s == 1)        printf(" Your input is wrong ! Please re-enter \n");    else        printf("\n The converted number is :%d",result);}void X_B(char a[],int k){    int i,j,s = 0;    int result = 0;    int b[50];    int p[30];      for (i = 0; i < k; i++)    {        if(a[i] <= '9' && a[i] >= '1')            b[i]=a[i]-48;        else        {            switch(a[i])            {            case 'A': b[i] = 10;                break;            case 'B': b[i] = 11;                break;            case 'C': b[i] = 12;                break;            case 'D': b[i] = 13;                break;            case 'E': b[i] = 14;                break;            case 'F': b[i] = 15;                break;            case 'a': b[i] = 10;                break;            case 'b': b[i] = 11;                break;            case 'c': b[i] = 12;                break;            case 'd': b[i] = 13;                break;            case 'e': b[i] = 14;               break;            case 'f': b[i] = 15;               break;           default:                  s = 1;           }        }     }     for (i = 1, j = k - 1; j >= 0; j--, i *=16)          result+=b[j]*i;     for (j = 0; result != 0; j++)     {          p[j] = result % 2;          result /= 2;     }    if(s == 1)         printf(" Your input is wrong ! Please re-enter \n");    else    {         printf("\n The converted number is :");         for (k = j - 1; k >= 0; k--)             printf("%d",p[k]);         printf("\n");    }}void X_O(char a[],int k){    int i,j,s = 0;    int result = 0;    int b[30];    int p[30];     for (i = 0; i < k; i++)    {        if(a[i] <= '9' && a[i] >= '1')            b[i]=a[i]-48;        else        {            switch(a[i])            {            case 'A': b[i] = 10;                break;            case 'B': b[i] = 11;                break;            case 'C': b[i] = 12;                break;            case 'D': b[i] = 13;                break;            case 'E': b[i] = 14;                break;            case 'F': b[i] = 15;                break;            case 'a': b[i] = 10;                break;            case 'b': b[i] = 11;                break;            case 'c': b[i] = 12;                break;            case 'd': b[i] = 13;                break;            case 'e': b[i] = 14;               break;            case 'f': b[i] = 15;               break;           default:                  s = 1;           }        }    }    for (i = 1, j = k - 1; j >= 0; j--, i *=16)         result+=b[j]*i;    for (j = 0; result != 0; j++)    {         p[j] = result % 8;         result /= 8;    }    if(s == 1)         printf(" Your input is wrong ! Please re-enter \n");    else    {         printf("\n The converted number is :");         for (k = j - 1; k >= 0; k--)             printf("%d",p[k]);         printf("\n");    }}



Refer to the answer 2:

copyright notice
author[CSDN Q & A],Please bring the original link to reprint, thank you.
https://en.primo.wiki/2022/02/202202030218338316.html

Random recommended