开发者

How do I (manually) calculate bitwise and and bitwise or between two numbers in hexadecimal form without converting it into binary at any step?

开发者 https://www.devze.com 2023-02-15 03:14 出处:网络
Lets say a = 0x6db7 and b = 0x736.How to compute a&b and a|b manually? I am aware of bitwise operations,and I know this can be solved by convertin开发者_如何学Cg a and b into it\'s binary form a

Lets say a = 0x6db7 and b = 0x736.How to compute a&b and a|b manually?

I am aware of bitwise operations,and I know this can be solved by convertin开发者_如何学Cg a and b into it's binary form and then bitwise operations and then again converting to hex,however what I am looking for is a solution that doesn't involve too much of calculation without the interdemidiate binary conversion.

Is it possible ?


Those are bitwise and and bitwise or. To compute them manually, convert each number to binary, then compute the result. The result of an and will be 1 if and only if the corresponding bits are set. The result of an or will be 1 if the corresponding bits in either one or the other or both are set:

 100111      100111
&110010     |110010
-------     -------
 100010      110111

After that, you normally want to convert the result back to some other base (e.g., hexadecimal).

0

精彩评论

暂无评论...
验证码 换一张
取 消