取十六进制数的高四位与低四位(20分)

  • 主题发起人 主题发起人 pyaxg
  • 开始时间 开始时间
P

pyaxg

Unregistered / Unconfirmed
GUEST, unregistred user!
如何取十六进制数的高四位与低四位?解释shr shl
 
shl = shift left // 左移X位,如:a shl 2 === a * 2^2 // 希望没有记错, 你测试一下
shr = shift right // 右移X位,a shr 2 == a div 2^2

得出高四位可能是:shr 4 // 向右退四位,
不一下正确, 以实际结果为准,哈哈

// delphi帮助
The following logical operators perform bitwise manipulation on integer operands. For example, if the value stored in X (in binary) is 001101 and the value stored in Y is 100001, the statement

Z := X or Y;

assigns the value 101101 to Z.

Logical (bitwise) operators
Operator Operation Operand types Result type Examples
not bitwise negation integer integer not X
and bitwise and integer integer X and Y
or bitwise or integer integer X or Y
xor bitwise xor integer integer X xor Y
shl bitwise shift left integer integer X shl 2
shr bitwise shift right integer integer Y shr I
The following rules apply to bitwise operators.

The result of a not operation is of the same type as the operand.
If the operands of an and, or, or xor operation are both integers, the result is of the predefined integer type with the smallest range that includes all possible values of both types.
The operations x shl y and x shr y shift the value of x to the left or right by y bits, which (if x is an unsigned integer) is equivalent to multiplying or dividing x by 2^y
the result is of the same type as x. For example, if N stores the value 01101 (decimal 13), then N shl 1 returns 11010 (decimal 26). Note that the value of y is interpreted modulo the size of the type of x. Thus for example, if x is an integer, x shl 40 is interpreted as x shl 8 because an integer is 32 bits and 40 mod 32 is 8.
 
同意楼上

高4位: = x shr 4
低4位: = x and 15
或者 = x shl 4 shr 4;
 
移位,怎么写了这么多 非 与 或 异或 左移、右移的英语咯!
 
procedure GetValue(var Hbyte,Lbyte: byte
value: WORD);
begin
HByte := Value shr 8;
lByte := Value and $00FF
end;
....
var
Hbyte,lbyte: byte;
begin
getvalue(hbyte,lbyte,$1234);//调用的结果为hbyte=$12,lbyte:=$34;
...
end;

shr 右移 byte类型是8位 word是16位 怎么移应该清楚了吧 $F换为二进制 1111 四位.
shl 左移


高四位:
 
这么简单的还用讨论
 
多人接受答案了。
 
后退
顶部