[Math] How to perform logical inclusive OR operation on hexadecimal numbers

elementary-number-theory

In logic there is so called OR operation that is quite clear to me as long as it is in the binary system. For example, if I want to OR such binary values as "101" (which corresponds to decimal "5") and "110" (which corresponds to decimal "6"), you would do it this way:

101

+

110

=

111

The logic here is quite clear: if there is at least one "1", then the result must also be "1".

However, I have no idea how this operation can be performed on hexadecimal numbers.
For example, if I needed to OR such hexadecimal values as "1A" (which corresponds to decimal "26") and "1F" (which corresponds to decimal "31"), how would i do that than?

1A

+

1F

=

??

Best Answer

To expand on copper.hat’s answer just a little, observe that every hexadecimal digit corresponds to a string of four bits:

$$\begin{array}{c|c} \text{Hex}&\text{Bin}\\ \hline 0&0000\\ 1&0001\\ 2&0010\\ 3&0011\\ 4&0100\\ 5&0101\\ 6&0110\\ 7&0111\\ 8&1000\\ 9&1001\\ A&1010\\ B&1011\\ C&1100\\ D&1101\\ E&1110\\ F&1111 \end{array}$$

Thus, any hexadecimal number converts very easily to binary: just convert the individual digits. Hex $B94A$, for instance converts to $1011\;1001\;0100\; 1010$. (That conversion is practically hard-wired, since I earned my spending money in college writing IBM 360 assembler language programs!)

Related Question