Advertisement
BladeMechanics

Temporaty Hex Function

Sep 28th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. void hex(int number)
  2. {
  3.     long int temp;
  4.     int i=-1,count,place;
  5.     int binary_c[25];
  6.     temp = binary(number); //convert the number to binary and assign it to temp
  7.     do
  8.     {
  9.         temp /= 10000;
  10.         i++;
  11.         //PASSEDprintf("\nStage 1 Temp(%d)\n", temp);
  12.     } while (temp);
  13.     //convert the number of bunches of 4 numbers in binary.
  14.     count = i;
  15.     //transfert the number to count.
  16.     temp = binary(number);
  17.     //reset temp to the binary version
  18.     ///PASSEdprintf("\nDebug temp(%d)", temp);
  19.     //PASSEDprintf("\nDebug number of digits(%d)", count);
  20.     do
  21.     {
  22.         binary_c[i] = (temp % 10000);
  23.         //PASSEDprintf("\nStage 2 binary_c[%d]=%d\n",i, binary_c[i]);
  24.         i--;
  25.         //PASSEDprintf("\nStage 2 i(%d)\n",i);
  26.         temp /= 10000;
  27.     } while (i>=0);
  28.     i = 0;
  29.     for (i; i <= count; i++)
  30.     {
  31.             temp = 0;
  32.             place = 1;
  33.             do
  34.             {
  35.                 temp += (binary_c[i] % 10)*place;
  36.                 place *= 2;
  37.                 binary_c[i]/= 10;
  38.                 //printf("\nStage 3 Temp(%d)\n", temp);
  39.                 //printf("\nStage 3 binary_c(%d)\n", binary_c[i]);
  40.                 //printf("\nStage 3 i(%d)\n", i);
  41.             } while (binary_c[i]);
  42.             if (temp < 10) printf("%c", temp + 48);
  43.             else printf("%c", temp + 55);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement