SByte(有符号)是16位,而不是8bit(最小值)

时间:2019-02-04 15:24:28

标签: windows powershell

我试图理解为什么SByte类型是16位而不是8位(又名:签名字符)。

$base = 2   

# 8-bit (char et unsigned char)

$("byte   : " + [byte]::MinValue.ToString() + " to " + [byte]::MaxValue.ToString())
$bin = [Convert]::ToString([byte]::MaxValue, $base).PadLeft(8, "0")
$($bin.Length.ToString() + "," + $bin)
$bin = [Convert]::ToString([byte]::MinValue, $base).PadLeft(8, "0")
$($bin.Length.ToString() + "," + $bin)

$("sbyte  : " + [sbyte]::MinValue.ToString() + " to " + [sbyte]::MaxValue.ToString())
$bin = [Convert]::ToString([sbyte]::MaxValue, $base).PadLeft(8, "0")
$($bin.Length.ToString() + "," + $bin)
$bin = [Convert]::ToString([sbyte]::MinValue, $base).PadLeft(8, "0")
$($bin.Length.ToString() + "," + $bin)

输出:

sbyte  : -128 to 127 (signed 8bit)
01111111
0x7f
1111111110000000
0xff80

如果这是由于二进制补码,这是我的操作系统还是硬件级别?

0 个答案:

没有答案