基本位操作 [英] Basic bits operation

查看:73
本文介绍了基本位操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单的问题,我认为:


我有一个已知字节,字节1:


0000 0100

和未知字节的已知部分,字节2:


bbbb 0100


我需要比较每个的低4位(0100)并确定是否

" byte 1,lower 4" ==字节2,低4。

什么是最有效的方式?

Simple question, I think:

I have a known byte, "byte 1":

0000 0100

and a known portion of an unknown byte, "byte 2":

bbbb 0100

I need to compare the lower 4 bits (0100) of each and determine if
"byte 1, lower 4" == "byte 2, lower 4".
What''s the most efficient way?

推荐答案

philbo30写道:
philbo30 wrote:

简单的问题,我认为:


我有一个已知的字节,字节1 ;:


0000 0100

和未知字节的已知部分,字节2:

bbbb 0100

我需要比较每个的低4位(0100)并确定是否

字节1,低4 ; ==字节2,低4。


什么是最有效的方法?
Simple question, I think:

I have a known byte, "byte 1":

0000 0100

and a known portion of an unknown byte, "byte 2":

bbbb 0100

I need to compare the lower 4 bits (0100) of each and determine if
"byte 1, lower 4" == "byte 2, lower 4".
What''s the most efficient way?



(a& amp; amp; ; 0x0f)==(b& x0f)


-

Ian Collins。

(a&0x0f) == (b&x0f)

--
Ian Collins.


Ian Collins写道:
Ian Collins wrote:

philbo30写道:
philbo30 wrote:

>简单问题,我认为:

我有一个已知字节,字节1:

0000 0100
和未知字节的已知部分,字节2:

bbbb 0100

我需要比较每个的低4位(0100)并确定是否
byte 1,lower 4。 ==字节2,低4。

什么是最有效的方式?
>Simple question, I think:

I have a known byte, "byte 1":

0000 0100

and a known portion of an unknown byte, "byte 2":

bbbb 0100

I need to compare the lower 4 bits (0100) of each and determine if
"byte 1, lower 4" == "byte 2, lower 4".
What''s the most efficient way?



(a& 0x0f)= =(b& x0f)

(a&0x0f) == (b&x0f)



哎呀,(a& 0x0f)==(b& 0x0f)


-

Ian Collins。

Oops, (a&0x0f) == (b&0x0f)

--
Ian Collins.


2007年8月11日星期六16:01:00 -0700,philbo30写道:
On Sat, 11 Aug 2007 16:01:00 -0700, philbo30 wrote:

简单的问题,我想:


我有一个已知字节,字节1:


0000 0100

和未知字节的已知部分,字节2:


bbbb 0100


我需要比较每个的低4位(0100)并确定是否

" byte 1,lower 4" ==字节2,低4。


什么是最有效的方法?
Simple question, I think:

I have a known byte, "byte 1":

0000 0100

and a known portion of an unknown byte, "byte 2":

bbbb 0100

I need to compare the lower 4 bits (0100) of each and determine if
"byte 1, lower 4" == "byte 2, lower 4".
What''s the most efficient way?



使用byte2& 15(或等效字节2%16,在这种情况下)

隔离低4位。然后比较

byte2的低四位和byte1的低四位(记住==绑定

比&更紧,所以请确保你有足够的括号)或者

如果你知道byte1总是8,则直接使用8。


-

Army1987(替换 NOSPAM与电子邮件)

没有人通过辞职来赢得比赛。 - S. Tartakower

Use byte2 & 15 (or equivalently byte2 % 16, in this case) to
isolate the lower four bits. Then compare the lower four bits of
byte2 with the lower four bits of byte1 (remember that == binds
more tightly than &, so make sure you have enough parentheses), or
directly with 8 if you know that byte1 is always 8.

--
Army1987 (Replace "NOSPAM" with "email")
No-one ever won a game by resigning. -- S. Tartakower


这篇关于基本位操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆