逻辑移位是指移动数字的所有物理位。
算术移位是指通过移位数字符号位以外的位,不改变符号位。
具体而言,在以二进制补数表现的负数的方式中,算术位移的表现形式是在最上位补数1。
当然你还没有学二进制补码。 就快到了。
如果负数的表示形式不是二进制补数(这很少见),算术位移并不一定在最高位补数1。
在汇编级,算术位移和逻辑位移是两个不同的指令。
java语言使用表示逻辑移位和表示算术移位的语言,因此有符号的数量也可以进行逻辑移位。
在c语言中,它只是表示位移。 有符号的数字通常使用“算术位移”而不是“绝对”。
“无符号数是逻辑,有符号数是算术”的推论并不严密。 虽然大多数情况下是正确的。
“thecstandarddoesnotpreciselydefinewhichtypeofrightshiftshouldbeused.forunsigneddata (I.e .
integralobjectsdeclaredwiththequalifierunsigned ),rightshiftsmustbelogical.forsigneddata (
default ),eitherarithmeticorlogicalshiftsmaybeused.thisunfortunatelymeansthatanycodeassuming
oneformortheotherwillpotentiallyencounterportabilityproblems.in practice,however,almost all
compiler/machinecombinationsusearithmeticrightshiftsforsigneddata,and many程序assume
this to be the case.'
已在CSAPP 2.1.10中明确写入。
forsigneddata(thedefault ),eitherarithmeticorlogicalshiftsmaybeused。
看完书,不等于看书。 能在半年内学好一本CS APP是个好成绩。