I am making a C program in which I have two hex numbers, i.e. num1=25
num2=71
which are in hex. I want to make it as num3=2571
and then I have to convert 2571
into a decimal number. How do I do this? Please help, Thanks!
Just shift the digits and combine
int num1,num2,num3;
num1=0x25;
num2=0x71;
num3=(num1<<8)|(num2);
printf("%x %d",num3,num3);
You need to place 25 (0025) followed by 71 (0071) in a variable, so you have to left shift the first number by 8 bits (0025 to 2500) and combine it with num2. Logical Or is the equivalent for combining, hence the |
symbol.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With