Advertisement
LarvitarYoung

BinaryToHex

Nov 6th, 2021
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.66 KB | None | 0 0
  1. #include<stdio.h>
  2. int power(int base,int exponent){
  3.     int dependant=base;
  4.     if(exponent<1){return 1;}
  5.     for(int i=1;i<exponent;i++){
  6.         dependant*=base;
  7.     }
  8.     return dependant;
  9. }
  10. void main(int argc, char const *argv[]){
  11.     int inputDigit,exponentCount=0,decimalFormat=0;
  12.     long int binaryFormat=0;
  13.     scanf("%d",&inputDigit);    
  14.     while (inputDigit==1||inputDigit==0)
  15.     {  
  16.         decimalFormat+=power(2,exponentCount)*inputDigit;
  17.         binaryFormat+=power(10,exponentCount++)*inputDigit;
  18.         scanf("%d",&inputDigit);
  19.     }
  20.     printf("Binary form: %ld \ntransform to HexaDecimal is %x \n",binaryFormat,decimalFormat);
  21. }
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement