2

When one byte is represented by 8 bits in binary notation you have a sequence of 8 possible 1's and 0's. So 00101010 can be shortened to 2A using hexadecimal notation. My book says you can shorten that representation by using hexadecimal after the 4th place from the right. For example...

00101010

can be represented with a mix of hexadecimal notation and binary notation by taking the 4 digits on the left 0010 and and representing that sequence to equal 2 in hexadecimal. I understand because 0010 equals 32 and when you are using hexadecimal notation that has a base of 16 that equals to 2.

What I don't understand is how the right side of the sequence is represented. My book says 1010 can be represented by the letter A which equals to 10. 1010 in binary notation equals 8 + 2 = 10. Here is the issue I'm having.

Applying the same concept to the right side as the left side of the 8 bit sequence shouldn't you divide the ride side 10 by 2 since binary notation is using the power of 2 like you divided the left side by 16 since you're using hexadecimal notation which has the power of 16? Am i thinking about it wrong?

Jessica M.
  • 1,451
  • 12
  • 39
  • 54

2 Answers2

2

Let's start with the complete 8-bit byte, writing the place value under each digit:

0 0 1 0 1 0 1 0
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
↓ ↓ ↓ ↓ 8 4 2 1
↓ ↓ ↓ 16
↓ ↓ 32
↓ 64
128

So, in base 10, this is 32 + 8 + 2 = 42.

If we split the 8-bit byte into two 4-bit nybbles, you have

0 0 1 0  1 0 1 0
↓ ↓ ↓ ↓  ↓ ↓ ↓ ↓
8 4 2 1  8 4 2 1

You'll notice each 4-bit nybble can hold a value from 0 to 15. So the nybbles can represent two hexadecimal digits.

We treat the two nybbles the same way when we calculate their values. From left to right, the digits in each nybble have place values 8, 4, 2, 1. So the upper (left) nybble has a value of 2, and the lower (right) nybble has a value of 8 + 2 = 10. As you wrote, the decimal number 10 is written as A in hexadecimal, so the hexadecimal byte is written 2A.

Remember, though, that this is hexadecimal. So the places values are powers of 16:

2 A
↓ ↓
↓ 1
16

So, converting back to decimal, 2A = 2×16 + 10 = 32 + 10 = 42.

Adam Liss
  • 47,594
  • 12
  • 108
  • 150
  • thanks. That seems like a really simple concept. I don't know why I got so confused. – Jessica M. Jul 29 '13 at 01:22
  • 1
    Just like in large decimal numbers, where each next digit (from right to left) represents a next power of 10, in hex you are counting by 16s. The first step is '1' (16 to the power 0), then 16. Next, for a hex value of `100` would be 256 -- 16*16 -- and then, for `1000` 4,096 -- 16*16*16. And so on. – Jongware Jul 29 '13 at 02:20
1

When converting binary to hexadecimal, the left 4 bits gets the same treatment as the right 4 bits. All that "binary to hex" does is replacing any sequence of 4 bits with a single hexadecimal digit -- at that stage you don't have to worry about conversion to a 'full' number.

Your example 00101010 can be split in two 4-bit sequences: 0010 and 1010. Converting each of these into hex is done by adding them up from right to left, multiplying each next bit by two. This is exactly what you ate used to in base-10; a value 532 represents "10^0 * 2 + 10^1 * 3 + 10^2 * 5" (where ^ is the usual shorthand for "power of"). So, for the first 4 bits you get

0*1 + 1*2 + 0*4 + 0*8 = 2

and the second set of 4 bits

0*1 + 1*2 + 0*4 + 1*8 = 10

In hexadecimal, each value from 0 to 15 is represented by a single 'digit', and we run out of single digits at 9. So starting at 10, we use A,B,C,D,E, and F to represent the decimal values 10, 11, 12, 13, 14, and 15.

Hence, the hex representation of 1010 is A; and your binary number translates to 2A.

Converting this, in turn, to decimal again also works the same as in decimal, only now each 'digit' represents a next power of 16. So this evaluates as

16 * 2 + 1 * A

or (decimal)

16 * 2 + 1 * 10 = 42

You can verify that this is the same decimal value as the starting binary 00101010 by adding up all of its binary numbers:

 1 * 0
 2 * 1
 4 * 0
 8 * 1
16 * 0
32 * 1
64 * 0
128 * 0
Jongware
  • 22,200
  • 8
  • 54
  • 100
  • Thanks for your input. The concept is simple after understanding how to correctly break down and interpret each 4 digit piece. – Jessica M. Jul 29 '13 at 01:22