>> 关于计算机有符号数的符号拓展(sign extension)问题
这里首先阐述相关规律, 情况为将位数较少的有符号存储空间中取出数据并放入更大有符号存储空间, 如: char → short .
规律: 将原空间符号位重复填充至新空间剩余位.
eg.(负数情况, 正数同理)
char: 1000 0000 →
short: 1111 1111 1000 0000
-------------------------------------------------------------------------------------------------
证明:
A = (1000 0000)2 = (-27 )10= (-128)10
B = (1111 1111 1000 0000)2 = (-215+214+213+......+28+27)10
=( 214(1-2) + 213 +......+27)10
=(-214+213+......+27)10
=(-27)10 = (-128)10 = A
得证该例.
---------------------------------------------------------------------------------------------
证明(一般性):
设A = (1X)2 = (-2n-1 )10 + (X)2
B = (11......1 1X)2 = (-2m-1+2m-2+......+2n+2n-1)10+(X)2
=(-2n-1)10 + (X)2 = A
得证.