1. Question:C code to convert decimal to hexadecimal 

    Answer
    #include<stdio.h>
    int main(){
        long int decimalNumber,remainder,quotient;
        int i=1,j,temp;
        char hexadecimalNumber[100];
    
        printf("Enter any decimal number: ");
        scanf("%ld",&decimalNumber);
    
        quotient = decimalNumber;
    
        while(quotient!=0){
             temp = quotient % 16;
    
          //To convert integer into character
          if( temp < 10)
               temp =temp + 48;
          else
             temp = temp + 55;
    
          hexadecimalNumber[i++]= temp;
          quotient = quotient / 16;
      }
    
        printf("Equivalent hexadecimal value of decimal number %d: ",decimalNumber);
        for(j = i -1 ;j> 0;j--)
          printf("%c",hexadecimalNumber[j]);
    
        return 0;
    }
    Sample output: Enter any decimal number: 45 Equivalent hexadecimal value of decimal number 45: 2D

    1. Report
  2. Question:Easy way to convert decimal number to hexadecimal number 

    Answer
    #include<stdio.h>
    int main(){
    
      long int decimalNumber;
    
      printf("Enter any decimal number: ");
      scanf("%d",&decimalNumber);
    
      printf("Equivalent hexadecimal number is: %X",decimalNumber);
    
      return 0;
    }
    Sample output: Enter any decimal number: 45 Equivalent hexadecimal number is: 2D

    1. Report
  3. Question:C program to convert binary to octal 

    Answer
    #include<stdio.h>
    #define MAX 1000
    int main(){
       
        char octalNumber[MAX];
        long int i=0;
    
        printf("Enter any octal number: ");
        scanf("%s",octalNumber);
    
        printf("Equivalent binary value: ");
        while(octalNumber[i]){
            switch(octalNumber[i]){
                 case '0': printf("000"); break;
                 case '1': printf("001"); break;
                 case '2': printf("010"); break;
                 case '3': printf("011"); break;
                 case '4': printf("100"); break;
                 case '5': printf("101"); break;
                 case '6': printf("110"); break;
                 case '7': printf("111"); break;
                 default:  printf("\nInvalid octal digit %c ",octalNumber[i]); return 0;
        }
        i++;
     }
    
        return 0;
    }
    Sample output: Enter any octal number: 123 Equivalent binary value: 001010011

    1. Report
  4. Question:C code to convert octal number to decimal number 

    Answer
    #include<stdio.h>
    #include<math.h>
    
    int main(){
       
        long int octal,decimal =0;
        int i=0;
    
        printf("Enter any octal number: ");
        scanf("%ld",&octal);
    
        while(octal!=0){
             decimal = decimal + (octal % 10) * pow(8,i++);
             octal = octal/10;
        }
    
        printf("Equivalent decimal value: %ld",decimal);
    
       return 0;
    }
    Sample output: Enter any octal number: 346 Equivalent decimal value: 230

    1. Report
  5. Question:C program to change octal to decimal 

    Answer
    #include<stdio.h>
    
    int main(){
       
        long int octalNumber;
    
        printf("Enter any octal number: ");
        scanf("%o",&octalNumber);
    
        printf("Equivalent decimal number is: %d",octalNumber);
    
        return 0;
    }
    Sample output: Enter any octal number: 17 Equivalent decimal number is: 15

    1. Report
  6. Question:C program for hexadecimal to binary conversion 

    Answer
    #include<stdio.h>
    #define MAX 1000
    
    int main(){
        char binaryNumber[MAX],hexaDecimal[MAX];
        long int i=0;
    
        printf("Enter any hexadecimal number: ");
        scanf("%s",hexaDecimal);
    
        printf("\nEquivalent binary value: ");
        while(hexaDecimal[i]){
             switch(hexaDecimal[i]){
                 case '0': printf("0000"); break;
                 case '1': printf("0001"); break;
                 case '2': printf("0010"); break;
                 case '3': printf("0011"); break;
                 case '4': printf("0100"); break;
                 case '5': printf("0101"); break;
                 case '6': printf("0110"); break;
                 case '7': printf("0111"); break;
                 case '8': printf("1000"); break;
                 case '9': printf("1001"); break;
                 case 'A': printf("1010"); break;
                 case 'B': printf("1011"); break;
                 case 'C': printf("1100"); break;
                 case 'D': printf("1101"); break;
                 case 'E': printf("1110"); break;
                 case 'F': printf("1111"); break;
                 case 'a': printf("1010"); break;
                 case 'b': printf("1011"); break;
                 case 'c': printf("1100"); break;
                 case 'd': printf("1101"); break;
                 case 'e': printf("1110"); break;
                 case 'f': printf("1111"); break;
                 default:  printf("\nInvalid hexadecimal digit %c ",hexaDecimal[i]); return 0;
             }
             i++;
        }
    
        return 0;
    }
    Sample output: Enter any hexadecimal number: 2AD5 Equivalent binary value: 0010101011010101

    1. Report
  7. Question:C program c program to convert binary to octal 

    Answer
    #include<stdio.h>
    int main(){
       
        long int binaryNumber,octalNumber=0,j=1,remainder;
    
        printf("Enter any number any binary number: ");
        scanf("%ld",&binaryNumber);
    
        while(binaryNumber!=0){
             remainder=binaryNumber%10;
            octalNumber=octalNumber+remainder*j;
            j=j*2;
            binaryNumber=binaryNumber/10;
        }
    
        printf("Equivalent octal value: %lo",octalNumber);
    
        return 0;
    }
    Sample output: Enter any number any binary number: 1101 Equivalent hexadecimal value: 15

    1. Report
  8. Question:C code for how to convert large binary to octal 

    Answer
    #include<stdio.h>
    #define MAX 1000
    
    int main(){
       
        char binaryNumber[MAX],octalNumber[MAX];
        long int i=0,j=0;
    
        printf("Enter any number any binary number: ");
        scanf("%s",binaryNumber);
    
        while(binaryNumber[i]){
          binaryNumber[i] = binaryNumber[i] -48;
          ++i;
        }
    
        --i;
        while(i-2>=0){
        octalNumber[j++] = binaryNumber[i-2] *4 +  binaryNumber[i-1] *2 + binaryNumber[i] ;
        i=i-3;
        }
    
        if(i ==1)
          octalNumber[j] = binaryNumber[i-1] *2 + binaryNumber[i] ;
        else if(i==0)
          octalNumber[j] =  binaryNumber[i] ;
        else
          --j;
    
        printf("Equivalent octal value: ");
        while(j>=0){
          printf("%d",octalNumber[j--]);
        }
    
        return 0;
    }
    Sample output: Enter any number any binary number: 1111111111111111111 1111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111 1111111111111111111111111111111111111111111111111111111 11111111 Equivalent octal value: 3777777777777777777777777777777 7777777777777777777777777777777777777777777777777777

    1. Report
  9. Question:C code for binary to decimal conversion 

    Answer
    #include<stdio.h>
    
    int main(){
       
        long int binaryNumber,decimalNumber=0,j=1,remainder;
    
        printf("Enter any number any binary number: ");
        scanf("%ld",&binaryNumber);
    
        while(binaryNumber!=0){
             remainder=binaryNumber%10;
            decimalNumber=decimalNumber+remainder*j;
            j=j*2;
            binaryNumber=binaryNumber/10;
        }
    
        printf("Equivalent decimal value: %ld",decimalNumber);
    
        return 0;
    }
    Sample output: Enter any number any binary number: 1101 Equivalent decimal value: 13

    1. Report
  10. Question:C program for hexadecimal to binary conversion 

    Answer
    #include<stdio.h>
    int main(){
       
        long int binaryNumber,hexadecimalNumber=0,j=1,remainder;
       
        printf("Enter any number any binary number: ");
        scanf("%ld",&binaryNumber);
       
        while(binaryNumber!=0){
        remainder=binaryNumber%10;
        hexadecimalNumber=hexadecimalNumber+remainder*j;
            j=j*2;
            binaryNumber=binaryNumber/10;
          }
       
        printf("Equivalent hexadecimal value: %lX",hexadecimalNumber);
    
        return 0;
    }
    Sample output: Enter any number any binary number: 1101 Equivalent hexadecimal value: D

    1. Report
Copyright © 2024. Powered by Intellect Software Ltd