week 2 (plus web zabra) cmsc
week 2 (plus web zabra) cmsc
Number Systems
A number system is a way of grouping a value.
Instead of this:
We can group the dots like this: 2 groups of 10, plus 8 or 28.
If they were eggs we might group them like this: 2 groups of 12, or 2 dozen, plus 4.
In the binary (base 2) number system we would group them like this: 1 group of 16, 1 group of 8, and 1
group of 4. (There are no groups of 2 or 1)
The number of dots in each picture is the same. They are just grouped differently.
The number system we use every day, the decimal number system, is based on 10.
The number 1043 means 1 group of 1000, 0 groups of 100, 4 groups of 10 and 3 groups of 1.
You cannot leave out the 0 in the 100s place. 1043 is not the same as 143.
The place values can also be written as powers of 10. The two rows in the table below have the same
values.
In the decimal system, there are 10 digits 0, 1, ,2, 3, 4, 5, 6, 7, 8, 9. There can only be 1 digit in a place.
You cannot put a 12 in the tens place. For 12 groups of 10, You would need to put a 2 in the 10s place,
and a 1 in the hundreds place: 120. Sometimes we called that carrying: We carry a 1 to the hundreds
place.
The binary number system is a place system. The right most place is the ones place. As we move from
right to left, each place is 2 times the previous place.
Place: 8 4 2 1
Digit: 1 0 1 1
Value: 1x8 0x4 1x2 1x1
The value of the binary number 10112 =1x8 + 0x4 + 1x2 + 1x1 = 8 + 4 + 2 = 1410.
For practical purposes we just add together the value of each place that has a one in it.
We read the binary number 1011 as "one zero one one." Do not say "one thousand eleven," those
terms refer to the decimal system.
The place values can also be written as powers of 2. The two rows in the table below have the same
values.
Place: 8 4 2 1
Power: 23 22 21 20
Place: 16 8 4 2 1
Digit: 1 1 0 1 1
We can write this as 110112 = 2710 Say this as "one one zero one one in the base 2 equals twenty seven
in the base ten." We often leave out "base 10" because that is the default number system for humans.
Place: 16 8 4 2 1
Digit: 1 1 1 0 1
Now add together the places that have a 1: 16+8+4+1= 29.
Place: 128 64 32 16 8 4 2 1
Digit: 1 0 1 1 1 0 0 0
Now add together the places that have a 1: 128+32+16+8= 184.
101110002 =18410
Place: 128 64 32 16 8 4 2 1
The next place would be 256, but we don't need it because 256 is more than 236, the number we are
converting.
Place: 128 64 32 16 8 4 2 1
Digit: 1
Now subtract 128 from 236: 236-128 = 108. In other words, we started with 236 and we used up 128
when we put a 1 in the 128 place, so we now have 108.
108 is more than 64, so we put a 1 in the 64 place and subtract 64.
Place: 128 64 32 16 8 4 2 1
Digit: 1 1
Now subtract 64 from 108: 108-65 = 44.
Place: 128 64 32 16 8 4 2 1
Digit: 1 1 1
Now subtract 32 from 44: 44-32 = 12.
Place: 128 64 32 16 8 4 2 1
Digit: 1 1 1 0
12 is more than 8, so put a 1 in the 8 place.
Place: 128 64 32 16 8 4 2 1
Digit: 1 1 1 0 1
12 is more than 8, so put a 1 in the 8 place and subtract 8 from 12. 12-8=4.
Place: 128 64 32 16 8 4 2 1
Digit: 1 1 1 0 1
The next place is the 4's place and we have 4 left. We put a 1 in the 4's place and put a 0 in each of the
remaining places:
Place: 128 64 32 16 8 4 2 1
Digit: 1 1 1 0 1 1 0 0
Hexadecimal
If we write a large number as a binary number, it can be quite long.
The hexadecimal, (hex) base 16, is used because every 4 binary digits can be represented by one
hexadecimal digit.
The table below shows the corresponding values of decimal, binary, and hexadecimal:
To convert a binary number to hexadecimal, first break it into groups of 4 starting on the right. You can
always add 0 on the left without changing the value of a number. If the left most group does not have 4
digits, just add zeroes on the left to make a group of 4. Then replace each group of 4 with the
corresponding hexadecimal digit from the table above.
0001,0110,1111,1011
1 6 F B
The place values in hexadecimal start with the ones place on the right, then multiply by 16 for each
place moving to the left:
The hexadecimal number 16FB is shown below with the place values:
4096 256 16 1
1 6 F B