Hi,
In the follwing code (simplified bit)
Code:unsigned short x = 0x18f;
int z = 8;
int y = (x & 0x0f ) + z;
cout << y ;
it is displaying, 17.. i was thinking it will be 23..
Printable View
Hi,
In the follwing code (simplified bit)
Code:unsigned short x = 0x18f;
int z = 8;
int y = (x & 0x0f ) + z;
cout << y ;
it is displaying, 17.. i was thinking it will be 23..
23 dec is 17 hex. Have you got a previous cout << hex somewhere? - as hex is sticky and stays until another output type is specified. On my system, the code in post #1 displays 23 in decimal.
Try :
Code:unsigned short x = 0x18f;
int z = 8;
int y = (x & 0x0f ) + z;
cout << dec << y ;
I tested this code with VS2019.
I see in the debugger window the value of y being
y 0x00000017 int
It is exactly 23 in decimal. :rolleyes:
Thanks a lot kaud, !. yes, i had somewhere else far before the cout << hex !. I also got this, and tried just after the post, with cout << dec. It worked :). Not sure why it should stay on !!!
yes i know, was wondering, why it should display in hex, unless i gave << hex explicitly. But it is confusing, that cout retains the previous << hex !!! Thanks Victor :)
AFAIK, the 'sticky' manipulators are:
Code:[no]boolalpha
[no]showbase
[no]showpoint
[no]showpos
[no]skipws
[no]unitbuf
[no]uppercase
dec/ hex/ oct
fixed/ scientific
internal/ left/ right
Thanks a lot, kaud for the info