Class Notes (1,100,000)
CA (620,000)
MacEwan (1,000)
Lecture 15

# CMPT-101 Lecture Notes - Lecture 15: Binary Number, Negative Number

Department
Computer Science
Course Code
CMPT-101
Professor
Nesrine Abbas
Lecture
15

This preview shows half of the first page. to view the full 3 pages of the document.
In binary, everything is calculated in 0s and 1s. Numbers and letters are both coded this way. It is the
simplest system to use in computers.
Every number system has a base. In decimal, the base is 10. When the 10 digits are cycled through
(0,1,2,3,4,5,6,7,8,9), the count restarts with 10, then 20, then 30. The order is the first digit (0), then the
second digit>first digit (10), then the third digit>first digit (20), until the next cycle.
In hexadecimal we use base 16, including letters after the numbers to represent values 10 through 16.
In binary, the base is 2.
001110211310041015110611171000810019
To convert binary to decimal, that each position on the binary number chart has a number correlation in
decimal.
First position, counting from the right, is 1. The second is 2. The third is 4. The fifth is 8. Sixth is 16.
Seventh is 32. Eighth is 64. Ninth is 132. And so on.
Take the number 01011
The first position has a 1. As do the second and fourth.
This means you can take the values of those positions and add them.
So first positions is 1, second position is 2, fourth position is 8; the number is 11.
Notice that in binary, the first position is always on for odd numbers and always off for even numbers.
Also notice that the number of digits in a binary number goes up with every power of 2. 1 is 1 digit, 2 is
2 digits, 4 is 3 digits, 8 is 4 digits, 16 is 5 digits, and 32 is 6 digits.
To convert from decimal to binary, write all powers of 2 until they exceed the number.
So for 30, write 1, 2, 4, 8, 16, 32 (32 exceeds the number 30, so stop).
Subtract the powers of 2 starting from the larger, continuing to subtract the largest number possible.
Every time you subtract, add a 1 (on position). Every time you can't, add a 0 (off position). If it's an
even number, add a 0 over the 1. If it's an odd number, add a 1.
32 16 8 4 2 1
0 1 1 1 1 0
30-16=14 ... 16-8=8 ... 8-4=4 ... 4-2=2
30 = 11110
Converting decimals to binary is fairly simple too. It's the same concept.
Take 3.14 for example. The period is placed in the middle. To the left of the period, 3 is written in
binary. To the right of the period, it works in the opposite way. The first position is 1/2, the second is
1/4, the third is 1/8, the fourth is 1/16, and the fifth is 1/32. Count out the fractions until they exceed the
decimal. So, for 14...
1/2 1/4 1/8 1/16
1 1 1 0
So 3.14 would be...
11.1110
Note that this works for fractions with even numbered ends.
find more resources at oneclass.com
find more resources at oneclass.com