0

How does hex work in c++?

int a = 15; cout << hex << a; //output is the small letter f I'm assuming that hex means hexadecimal. From the chart, decimal value of 15 gives hexadecimal value of 0F. Reference chart: https://www.oreilly.com/library/view/ccna-routing-and/9780134466163/app01.html Question 1: Is 0F the same as f? Is there some sort of conversion rule? Question 2: Does the second << operator in the last line of code have a special meaning? Does it mean that the decimal value of variable a is to be converted to a hex value (instead of printing two different things)?

1st Aug 2020, 10:14 PM
Solus
Solus - avatar
1 Resposta
+ 4
http://www.cplusplus.com/reference/ios/hex/ It doesn't matter what kind F/f will you use. It represent just a 15th position in the hexadecimal system. The value of "a" is converted to hex representation.
1st Aug 2020, 11:07 PM
electron
electron - avatar