Tuesday, February 10, 2015

Octal to Hexadecimal

/* Convert Octal number to Hexadecimal number */ int main() { long int octal, decimal = 0; int i=0, j, temp; printf("Enter any octal number: "); scanf("%ld", &octal); while(octal != 0){ decimal = decimal + (octal % 10) * pow(8, i++); octal = octal/10; } long int remainder, quotient; char hexadecimalNumber[100]; i=1; quotient = decimal; 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 is: "); for(j = i-1; j> 0; j--) printf("%c", hexadecimalNumber[j]); getch(); return 0; }

Share

& Comment

0 comments:

Post a Comment

 

Copyright © 2015 Code Fervor™ is a registered trademark.

Designed by Templateism By Naman Kumar