+ 1
sum of Hex
Hi Guys, I encounter an issue regarding summing of 2 hex numbers I cannot find the right function / syntax for summing these 2 values introduced from the keyboard : per ex: i introduce a= with a8 and b= bc5 , the results are 000a8 and 00bc5 and i need to sum these 2 hex numbers Can I get some help Regards
4 Réponses
+ 1
Took me a while to figure out but here is the code
https://code.sololearn.com/WUAg67Cd8Rae/#js
it is highly recommended that you learn a how to convert decimal s to hexadecimals the mathematical way before attempting to create an algorithm
please note: this algorithm uses a lookup table to identify the hex character and so gives you more control and allows you to see what is going on under the hood. other examples ive seen use the .toString(16) to convert to hexadecimal so you dont really see what is happening.
+ 2
hex numbers are prefixed with 0x, for example 0xbc5+0xa8
+ 1
ok, thanks, but how can I get the syntax in order to have the sum per ex:
1CEC + BEC = 28D8
i have tried some syntax that is written like this : cout << "The sum is "<<std::hex<< a + b << "." << endl; but the result is only 28 not 28D8
thanks
+ 1
I dont know how atm but will try to figure it out how to do it. Keep us posted if you figure it out before then