Practical Coding in Java

Learn to write and validate your own code

Darren Kessner, PhD

(revised September 1, 2025)

Previous: Binary

Converting between Hex and Binary

One hex digit corresponds to 4 bits, which makes it easy to convert between hex and binary.

Example

\[ \begin{aligned} \fbox{ 7 } \fbox{ C } &= \underset{7}{\fbox{0111}} \underset{C}{\fbox{1100}} \\ \\ \text{0x}7C &= 0111 \, 1100 \, _\text{BIN} \end{aligned} \]

Example

\[ \begin{aligned} \fbox{ F } \fbox{ F } &= \underset{F}{\fbox{1111}} \underset{F}{\fbox{1111}} \\ \\ \text{0x}FF &= 1111 \, 1111 \, _\text{BIN} \end{aligned} \]

Example

\[ \begin{aligned} \fbox{ 2 } \fbox{ 9 } \fbox{ A } &= \underset{2}{\fbox{0010}} \underset{9}{\fbox{1001}} \underset{A}{\fbox{1010}} \\ \\ \text{0x}29A &= 0010 \, 1001 \, 1010 \, _\text{BIN} \end{aligned} \]


Next: