+ 1

How is the hexadecimal numbers translated?

why this behavior? https://code.sololearn.com/cMA8qPbY7SmI/?ref=app

26th Jan 2019, 6:02 PM
Daniel Bandeira
Daniel Bandeira - avatar
6 odpowiedzi
+ 4
Try with this: printf("Varible a is equal to 0xE0? %d", a == (char)0xE0); You can also declare a as an unsigned char instead. The thing is, this 0xE0 is considered to be an int, so the variable a is cast to an int for the comparison, and since its value is negative (leftmost bit at 1), it becomes 0xffffffE0 when sign-extended. https://code.sololearn.com/cZgn97tb2b11/?ref=app
26th Jan 2019, 6:09 PM
Zen
Zen - avatar
+ 2
0x just means it is using hexadecimal notation.
26th Jan 2019, 6:43 PM
Zen
Zen - avatar
+ 2
EDIT: Maybe you know this already... Hexadecimal is essentially a number system with 6 new characters: a, b, c, d, e and f. It is case-insensitive. So, instead starting the second digit once you get past 9, you keep going until you get past f. This means hexademical is a base 16 number system. The normal decimal system is base 10. Binary is base 2. This is me counting from 0 to 20 in hexadecimals... 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, a, b, c, d, e, f, 10, 11, 12, 13, 14. In hexadecimals the highest two digit number is ff, which is 255 in regular decimals. This allows a RBG colour to be stored in six digits.
26th Jan 2019, 8:29 PM
James
James - avatar
0
but doesn't occur any extansion/casting in my code. or happens? The 0xE0 is trated as int by the compiler???
26th Jan 2019, 6:24 PM
Daniel Bandeira
Daniel Bandeira - avatar
0
really... I was thinking that the expression in 0x was a byte size. Wrong suposition. Thank to to show me that
26th Jan 2019, 6:27 PM
Daniel Bandeira
Daniel Bandeira - avatar
0
In my mind,the things would work as 0xFF (char) 0xFFFFFFFF (int) 0xFFFFFFFFFFFFFFFF (long) and go on... lololol
26th Jan 2019, 6:53 PM
Daniel Bandeira
Daniel Bandeira - avatar