I have been dealing with an issue with MATLAB when trying to visualize the binary representation of large integers and it has really confused me. I am working on a little-endian machine and positive int64
values. Therefore, the most significant bit (MSB) is always 0. All the other bits can be 0 or 1. I noticed that when I check the binary structure of large values many bits on the least significant bits (LSB) side are 0. For instance:
>> dec2bin(4611695988848162845, 64)
ans =
'0100000000000000000010010001000101101011011000110111100000000000' % WRONG!
>> dec2bin(4611695988848162846, 64)
ans =
'0100000000000000000010010001000101101011011000110111100000000000' % <--- WRONG and identical to above!
While the correct binary representation of value 4611695988848162845 should be:
Correct binary representation of 4611695988848162845:
'0100000000000000000010010001000101101011011000110111100000011101'
You can verify the correct binary structure here or use a simple C++ code to verify this. Can someone please explain to me what happens here? Doing dec2bin(int64(4611695988848162845), 64)
does not seem to help either.