I'm trying to bit shift char values into an unsigned long long (or an uint64_t, or an __int64), and whenever I try to bit shift by values greater than 32, it appears to subtract 32 from the size of the bit shift.
Other questions listed here a duplicates don't immediately state that a char
will be upgraded to only an int
instead of an unsigned long long
. Because this was not apparent to me, I didn't know that the rule of not shifting a bit-shifting a value by longer that its size was relevant.
The comments pointed out that the char
only becomes an int
and therefore can't isn't upgraded to a 64-bit int before assignment.
Code
#include <stdint.h>
#include <iostream>
#include <string>
#include <algorithm>
int main(...)
{
std::string text = "Saturday 2019-08 August-31__08:46:32.38948-pm Pacific Daylight time-phoneid:xxxxxxxxxxx-xxxxxxxx";
//unsigned int val1, val2, val3;
//val1 = val2 = val3 = 0;
//val1 = 't';
//val1 = val1 << 24;
//std::cout << val1 << std::endl;
//unsigned long long hash[12];
//uint8_t hash_count = 0;
//uint8_t shift_offset = 7;
//uint8_t hash_iter = 0;
for (unsigned int ii = 0; ii < text.size(); ii+=8)
{
unsigned long long test_01 = text[ii] << 56 ;
unsigned long long test_02 = text[ii+1] << 48 ;
unsigned long long test_03 = text[ii+2] << 40 ;
unsigned long long test_04 = text[ii+3] << 32 ;
unsigned long long test_05 = text[ii+4] << 24 ;
unsigned long long test_06 = text[ii+5] << 16 ;
unsigned long long test_07 = text[ii+6] << 8 ;
unsigned long long test_08 = text[ii+7] << 0;
//hash_iter++;
}
return 0;
}
How do I know it's not working?
I'm looking at the values inside the memory window in Visual Studio
System
Windows 10 Visual Studio 2015 Compile Configuration: Debug, x64