使用 dec2bin 的 MATLAB 中的二进制表示问题

Binary Representation Issue in MATLAB Using dec2bin

在尝试可视化大整数的二进制表示时,我一直在处理 MATLAB 的问题,这让我很困惑。我正在使用小端机器和正 int64 值。因此,最高有效位 (MSB) 始终为 0。所有其他位都可以为 0 或 1。我注意到,当我检查大值的二进制结构时,最低有效位 (LSB) 侧的许多位都是 0。对于实例:

>> dec2bin(4611695988848162845, 64)

ans =

    '0100000000000000000010010001000101101011011000110111100000000000' % WRONG!     
>> dec2bin(4611695988848162846, 64)

ans =

    '0100000000000000000010010001000101101011011000110111100000000000' % <--- WRONG and identical to above!

而值 4611695988848162845 的正确二进制表示应该是:

Correct binary representation of 4611695988848162845:
'0100000000000000000010010001000101101011011000110111100000011101'

您可以验证正确的二进制结构here or use a simple C++ code来验证这一点。有人可以向我解释这里发生了什么吗? dec2bin(int64(4611695988848162845), 64) 似乎也无济于事。

'Casting' 到 int64dec2bin(int64(4611695988848162845), 64) 确实适用于我的 R2020a 安装。

要解释您输入的结果不正确的原因,请查看 help dec2bin:

... If D is greater than flintmax, dec2bin might not 
    return an exact representation of D.