Program To Convert Hexadecimal To Decimal In 8051

C++ Program to convert hexadecimal to decimal with std::hex

ConvertConvert

Program To Convert Hexadecimal To Decimal In 8051 C

C Program To Convert Hexadecimal To Decimal Number. Let us learn how to convert hexadecimal to decimal number in C programming language. This C code for hexadecimal number to decimal conversion makes use of pow function, while loop and for loop. A hexadecimal number is at location 40h and we need to convert it to BCD 2. Value stored at r0 is 40h 3. At the address 40h value is FFh 4. Result stored in unpacked BCD form as ones digit at r3, tens value at r2, hundred value at r1 Before we start with actual coding lets revise about BCD.

2
4
6
8
10
12
14
16
18
20
22
24
26
28
30
32
34
36
38
40
42
44
46
48
50
52
54
56
58
60
62
64
* Converting Hexadecimal to Decimal in C++ codebind.com
*/
#include<stdlib.h>
#include<math.h>
char*hexstr;
constintbase=16;// Base of Hexadecimal Number
inti;
// Now Find the length of Hexadecimal Number
length++;
hexstr=hex;
// Compare *hexstr with ASCII values
if(*hexstr>=48&&*hexstr<=57){// is *hexstr Between 0-9
decnum+=(((int)(*hexstr))-48)*pow(base,length-i-1);
elseif((*hexstr>=65&&*hexstr<=70)){// is *hexstr Between A-F
decnum+=(((int)(*hexstr))-55)*pow(base,length-i-1);
elseif(*hexstr>=97&&*hexstr<=102){// is *hexstr Between a-f
decnum+=(((int)(*hexstr))-87)*pow(base,length-i-1);
else{
}
}
voidmain(){
charhex[9];// 8 characters for 32-bit Hexadecimal Number and one for ' '
std::cout<<' Enter 32-bit Hexadecimal Number : ';
std::cout<<'Value in Decimal Number is '<<decnum<<'n';
getch();
/*
Enter 32-bit Hexadecimal Number : 10