sum of Hex | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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

7th Jun 2019, 8:01 AM
Cristian Pupaza-Bacioiu
Cristian Pupaza-Bacioiu - avatar
4 Antworten
+ 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.
9th Jun 2019, 6:53 AM
Logomonic Learning
Logomonic Learning - avatar
+ 2
hex numbers are prefixed with 0x, for example 0xbc5+0xa8
7th Jun 2019, 8:22 AM
Logomonic Learning
Logomonic Learning - avatar
+ 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
7th Jun 2019, 1:10 PM
Cristian Pupaza-Bacioiu
Cristian Pupaza-Bacioiu - avatar
+ 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
7th Jun 2019, 8:12 PM
Logomonic Learning
Logomonic Learning - avatar