0
$\begingroup$

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

=

??

3 Answers 3

8

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

  • 1
    Engineers used to (and still do) use some particular bit patterns because they are easily recognizable in hex. For example, AAAA, 5555, DEADBEEF,...2012-08-31
  • 0
    For quick reference, you can even make a 16-by-16 table of the results, all in hexadecimals. Well, maybe that's not quicker :P BTW, I like copper.hat's DEADBEEF!2012-08-31
4

Treat the hex number as binary. $1A_{16} = 11010_2$, $1F_{16} = 11111_2$, so the 'or' is clearly $1F_{16}$.

0

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.

  • 0
    Also, NOT can be though of (100% - value%). When dealing with only 1s and 0s (100%s and 0%s) this is pretty simple: not(1)=1-1=0, not(0)=1-0=1, but we can follow the same rules for hexadecimal. not(5)=F-5=A, not(A)=F-A=5. (This is similar in concept to the not used on subsets of sets as well)2018-10-06
  • 0
    Using Not and Or, and DeMorgan's Law, we can create an And gate too! XY=(X'+Y')' so in hexadecimal: XY=(F-((F-X)+(F-Y))) which ends up being a "Which Ever Is Least" gate. This (and the other two) makes sense with any Natural Number based number systems.2018-10-06