简体   繁体   中英

The binary format for different data types

What is the exact binary format of a unsigned long long type (at least in visual studio).

I am doing some bit-wise operation with aliasing pointers, I set the bit through operations on unsigned char pointers then doing some other operations on unsigned long long pointers(alias).

The format of unsigned long long looks weird and because of this, it mess up the results, also, it seems that the bit-shift operation also behave strangely:

From bit-mask test it seems that this data is arranged from right: LSB->MSB : left , which means a >> shift will take the data to its more significant bit instead of the less ones, is this correct?

The compiler being ICC 13.0, and the OS is windows 7-64.

The byte layout you describe is little endian, which is the layout that Intel processors use in general. Bit shifts don't depend on the memory layout of the number, but rather the value, so endianness should not impact the value of your operations. If you are using pointer aliasing, however, like casting to a char * and using pointer arithmetic to extract segments of it, you will get endianness-dependent behaviour which, on little endian Intel processors, might not be what you were expecting.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM