获取一个字节的高4位

Ism*_* Dz -1 delphi byte bits bit

我试图获得a的高4位Byte.

那是我到目前为止的尝试:

function Upper4Bits(const X : Byte): Byte;
type 
   BS = set of 0..7;
var 
   K : Byte; Q: BS;
begin
  Q := [];
  for K := 0 to 3 do {is it right? upper?}
    {what i need here?}
    Include(Q, {what i put here});

  Upper4Bits := Byte(Q)
end;
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Uwe*_*abe 8

根据你对kotlinski答案的评论,你想要result := (byte1 and $F0) or (byte3 and $0F).

  • 因此,OP需要一个字节的高四位,而另一个字节的低四位,而不仅仅是高四位用shr移动.希望OP花一些时间更准确地问他的问题. (2认同)

Ian*_*oyd 6

在此输入图像描述

  • +1用于窃取我的想法并制作PNG!(太糟糕了,你左右混淆.) (9认同)
  • 第二个是不正确的.它不应该是SHL,而是SHR. (2认同)