Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- int power(int base,int exponent){
- int dependant=base;
- if(exponent<1){return 1;}
- for(int i=1;i<exponent;i++){
- dependant*=base;
- }
- return dependant;
- }
- void main(int argc, char const *argv[]){
- int inputDigit,exponentCount=0,decimalFormat=0;
- long int binaryFormat=0;
- scanf("%d",&inputDigit);
- while (inputDigit==1||inputDigit==0)
- {
- decimalFormat+=power(2,exponentCount)*inputDigit;
- binaryFormat+=power(10,exponentCount++)*inputDigit;
- scanf("%d",&inputDigit);
- }
- printf("Binary form: %ld \ntransform to HexaDecimal is %x \n",binaryFormat,decimalFormat);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement