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
=
??
$\endgroup$ 03 Answers
$\begingroup$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!)
$\endgroup$ 2 $\begingroup$Treat the hex number as binary. $\text{1A}_{16} = 11010_2$, $\text{1F}_{16} = 11111_2$, so the 'or' is clearly $\text{1F}_{16}$.
$\endgroup$ $\begingroup$The other answers here are based on converting from hexadecimal to binary, then computing a bitwise OR. I would like to propose a different method without converting to a different base.
Where my idea comes from: (not-tested) A standard diode in electronics only allows electricity to go one way. A simple OR gate in electronics is two diodes pointing into each other. If you were to put a high voltage through one side (F) the output would be that same voltage (F). Even if you added a lower voltage (A) to the other input, the output would remain the same as the output is already at a higher voltage.
So, our current OR gates really end up being "Which Ever Is Greater" gates. That would mean your example of 1A+1F = 1F. Also, 5B+A0=AB. This is very different than a binary bitwise OR, but that is because it is a "true" hexadecimal bitwise OR.
$\endgroup$ 3