Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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

=

??

share|improve this question
add comment

2 Answers 2

up vote 5 down vote accepted

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

share|improve this answer
1  
Engineers used to (and still do) use some particular bit patterns because they are easily recognizable in hex. For example, AAAA, 5555, DEADBEEF,... –  copper.hat Aug 31 '12 at 6:19
    
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! –  Tunococ Aug 31 '12 at 6:27
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.