Quixotic
Quixotic

Reputation: 2464

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

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 converting 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 ?

Upvotes: 1

Views: 7119

Answers (1)

Jerry Coffin
Jerry Coffin

Reputation: 490288

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).

Upvotes: 1

Related Questions