C语言的一个问题。
Assumeaprogrammerwrotethefollowingvariabledeclarations.Theinitialvalueshavebeenomitte...
Assume a programmer wrote the following variable declarations. The initial values have been omitted (. . . ), but you are provided with the representations of the variable values in memory. unsigned char uc = ...; // 00001100 in memory signed char sc = ...; // 11111011 in memory What initial values did the programmer specify with variables uc and sc? • Hint: For a signed variable, the representation of the variable’s value in memory will be in two’s complement. For an unsigned variable, the representation will be binary.
展开
1个回答
展开全部
简单来卜脊说,题目问的是:
uc是unsigned char,内存中二进制表示是00001100。
sc是signed char,内存中二进制表示的是11111011。
求uc,sc的初值。
unsigned char是无符号的,00001100就是十进制中的12。
signed char是有符号的,在内存中以补码形式存在,
11111011首位是1,因此是负数,
按位取反,末尾加1得到:00000101是型春渗十进森坦制的5,
因此是-5.
所以:
unsigned char uc=12;
signed char sc=-5;
uc是unsigned char,内存中二进制表示是00001100。
sc是signed char,内存中二进制表示的是11111011。
求uc,sc的初值。
unsigned char是无符号的,00001100就是十进制中的12。
signed char是有符号的,在内存中以补码形式存在,
11111011首位是1,因此是负数,
按位取反,末尾加1得到:00000101是型春渗十进森坦制的5,
因此是-5.
所以:
unsigned char uc=12;
signed char sc=-5;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询