I have a string:
“the quic”
Which is passed on to a function where the bits that make up the string are stored in an unsigned __int64. Resulting in the following output:
0111010001101000011001010010000001110001011101010110100101100011
However when I pass a string containing these values:
0xDE, 0x10, 0x9C, 0x58, 0xE8, 0xA4,
0xA6, 0x30, ‘\0’
The output isn’t as correct as I expected:
1111111111111111111111111111111111111111111111111010011000110000
I’m using the same code as in the first string, which reads:
(((unsigned __int64)Message[0]) << 56) | (((unsigned __int64)Message[1]) << 48) |
(((unsigned __int64)Message[2]) << 40) | (((unsigned __int64)Message[3]) << 32) |
(((unsigned __int64)Message[4]) << 24) | (((unsigned __int64)Message[5]) << 16) |
(((unsigned __int64)Message[6]) << 8) | (((unsigned __int64)Message[7]));
I guess you did something like this,
change it to unsigned char will solve your problem,
I’ve tried both, the char version will be wrong in VC++, but unsigned version will be correct.
If you want to know the reason, look at a simpler version,
What’s the difference? 0xDE is an int type. For the first one, you are converting int to signed char, for the second one, you are converting int to unsigned char.
From standard 4.7/2, 4.7/3