Concept
How do you convert between binary and hexadecimal using nibbles?
Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk / Chapter 1
"b 1 ÷ 2 c = 0 . We’re done. The final answer is 110001 2 . Double-checking our work, we verify that indeed one 32 plus one 16 plus one 1 gives 49, which is what we started with. Converting to and from hex That was pretty tedious. But converting back and forth from binary to hex is a snap. That’s because 16 is exactly 2 4 , and so one hex digit is exactly equal to four binary digits. This isn’t the case with base 10, where one decimal digit is equal to three binary digits… plus a little extra. This “not quite a whole number of digits” thing is what makes converting from decimal to binary (or decimal to hex, for that matter) so awkward. We most commonly deal with sets of eight bits at a time, which is called a byte . (This is the fundamental unit of storage on pretty much every computer on earth.) Suppose I had the following byte: 10000110 2 Because one hex digit is exactly equal to four bits, this byte is exactly equal to: 86 16\n\n7.4. BINARY (BASE 2) 177 This is because the byte can be neatly split into two parts: 1000 , which corresponds to the hex digit 8, and 0110, which corresponds to the hex digit 6. These two halves are called nibbles — one byte has two nibbles, and each nibble is one hex digit. At a glance, therefore, with no multiplying or adding, we can convert from binary to hex. Going the other direction is just as easy. If we have: 3E 16 we just convert each hex digit into the corresponding nibble: 00111110 2 After you do this a while, you get to the point where you can instantly recognize which hex digit goes with which nibble value. Until then, though, here’s a handy table: nibble hex digit 0000 0 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7 1000 8 1001 9 1010 A 1011 B 1100 C 1101 D 1110 E 1111 F In case you’re wondering, yes this is worth memorizing."
Related Ideas
- What is the binary number 1011001110101010₂ in hexadecimal?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1
- Why is hexadecimal used in computer science, and what do its digits represent?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1
- How do place values and counting work in binary?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1
- How do you convert between binary and decimal?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1
- How can you convert a decimal number to hexadecimal using modulo and floor?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1
- How much information can one or more bytes store?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1
- Why is binary, or base 2, used in computer science?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1
- How are numbers interpreted in a base 7 system?Stephen Davies, Ph.D. Version 2.2.2 Through Discrete Mathematics A Cool Brisk Walk · Chapter 1