Professional Documents
Culture Documents
Position 2 1 0
weight 102 = 100 101 = 10 100 = 1
Hence, the above number ①⑦⑤ will be placed in the table starting from the right
and moving leftwards.
Position 2 1 0
weight 102 = 100 101 = 10 100 = 1
Number ① ⑦ ⑤
To obtain the final value of the above number: Each digit is multiplied by the
corresponding weight of its column, then they are all added together
① * 100 + ⑦ * 10 + ⑤ * 1 = 100 + 70 + 5 = 175
Position 2 1 0
weight N2 N1 N0 = 1
o To obtain the final value of any number in the table, you multiply each digit by its weight
and add them all up
Base 2 (N = 2)
- Base 2:
o If each value to be represented requires only 1 digits, then we need 2 digits to represent
2 different values
o Digits range from 0 till 1 (0 and 1)
o To represent values greater than 2, we need to use more digits. These digits are written
next to each other and interpreted in a way to reach higher values
Position 2 1 0
weight 22=4 21=2 20 = 1
Number 0 1 1
o To obtain the final value of any number in the table, you multiply each digit by its weight
and add them all up. Final value = 0*4 + 1*2 + 1*1 = 0 + 2 + 1 = 3
Some Definitions
Data storage, such as memory capacity, is measured in Bytes, such as GB. Please note the use of
uppercase B (B=Byte). This is because, storage devices work with blocks of 8 bits at a time rather than
only 1 bit
Using 2 bits
Position 1 0
weight 21=2 20 = 1
Number 1 0
1*2 + 0*1 = 2+0=2 (10)2 = (2)10
Position 1 0
weight 21=2 20 = 1
Number 0 1
0*2 + 1*1 = 0+1=1 (01)2=(1)10
- When we multiply 0 by a power of 2, we get 0 If, in a bit position, we use 0, then we just skip
passed the corresponding power of 2
- When we multiply 1 by a power of 2, we get the corresponding power of 2 value if, in a bit
position we use 1, then we will use the corresponding power of 2 in the addition to obtain the
equivalent decimal number
- As a conclusion, when converting from binary to decimal:
o We add the powers of 2 (weight) where we have 1
o We ignore the powers of 2 (weight) where we have 0
Using 3 bits
Position 2 1 0
2
weight 2 =4 21=2 20 = 1
Number 0 1 0
0*4+1*2+0*1=0+2+0=2 (010)2=(2)10
Position 2 1 0
Weight 22=4 21=2 20 = 1
Number 1 0 1
4+1=5 (101)2=(5)10
Position 2 1 0
Weight 22=4 21=2 20 = 1
Number 1 1 1
4+2+1=7 (111)2=(7)10
Using 4 bits
Position 3 2 1 0
weight 23=8 22=4 21=2 20 = 1
Number 1 0 0 1
8+1=9 (1001)2=(9)10
Using 8 bits
Position 7 6 5 4 3 2 1 0
weight 27=128 26=64 25=32 24=16 23=8 22=4 21=2 20 = 1
Number 1 0 0 1 1 0 1 0
128+16+8+2=154 (10011010)2=(154)10
To convert from decimal to binary, we divide the number by 2 and record the remainder. We continue
until we reach either 0 or 1 at the end:
77 / 2 = 38 Remainder = 1
38 / 2 = 19 Remainder = 0
19 /2 = 9 Remainder = 1
9/2=4 Remainder = 1
4 /2 = 2 Remainder = 0
2/2=1 Remainder = 0
10011010
Example 2: (64)10=(100000)2
64 / 2 = 32 Remainder = 0 (Right)
32 / 2 = 16 Remainder = 0
16 / 2 = 8 Remainder = 0
8/2=4 Remainder = 0
4/2=2 Remainder = 0
2/2=1 Remainder = 0
(64)10=(1000000)2
Example 3: (25)10=(11001)2
25 / 2 = 12 Remainder = 1 (Right)
12 / 2 = 6 Remainder = 0
6/2=3 Remainder = 0
3/2=1 Remainder = 1
(25)10=(11001)2
To represent number (25)10 in binary, we only needed 5 bits. But sometimes, we might be asked to write
this number using 8 bits. To do so, we simply add 0s to the left. Using 8 bits: (25)10=(00011001)2
75 / 2 = 37 Remainder = 1
37 / 2 = 18 Remainder = 1
18 /2 = 9 Remainder = 0
9/2=4 Remainder = 1
4 /2 = 2 Remainder = 0
2/2=1 Remainder = 0
01001011
Position 7 6 5 4 3 2 1 0
weight 128 64 32 16 8 4 2 1
0 1 0 0 1 0 1 1
0 0
0 1
1 0
1 1
With 2 bits, we can get 4 different values (22=4)
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
With 3 bits, we can get 8 different values (23=8)
Hexadecimal
Hexadecimal, also referred to as Hex Base 16
Every digit should represent one of 16 different values. We need 16 digits in total, where each digit will
have a value from 0 to 15
We now need 1 digit to represent the values of 10, 11, 12, 13, 14, and 15. So we will rely on the first 6
alphabet letters where each letter will be assigned for a Hex value:
A 10
B 11
C 12
D 13
E 14
F 15
Example 1: (37)16
Position 1 0
weight 161=16 160 = 1
Number 3 7
3*16+7*1= 48+7 = 55
(37)16=(55)10
To make calculation easier, we will use the binary system as an intermediate numbering system to
transition from Hex to Decimal and vice versa.
Convert from Hex to Binary:
8 4 2 1
(37)16=(0011 0111)2=(55)10
- We proceed one Hex digit at a time starting from the leftmost Hex digit
- Convert each Hex digit to binary
- Group the resultant bits together
- Convert the resultant binary number to decimal
3 2+1 = 0011
7 4+2+1=0111
Convert from binary to Hex. If we have less than 4 bits for each hex digits, we just add 0 to the left
0+1=1
1+0=1
1+1=0 Carry 1 10
Example 1:
2+6=8
1 1
0 1 0
1 1 0
1 0 0 0
Example 2:
6+5=11
1
1 1 0
1 0 1
1 0 1 1
Example 3:
6+7=13
1 1
1 1 0
1 1 1
1 1 0 1
When using x bits to represent an integer using 2’s complement notation, the leftmost bit is used as a
sign bit. Hence, calculation to convert from binary to decimal is done using the remaining (x-1) bits. As
an example, if we use 4 bits to represent integers using two’s complement notation, the leftmost bit is
the sign bit and calculation is done using the remaining 3 bits.
As a result, the largest positive integer is: 0111 = +7. With two’s complement notation, the
largest positive number is no longer 1111=15. Now it is 0111= +7. Range of positive integers:
07, totaling 8 different values.
The remaining 8 values are the negative numbers. They will range from -1 to -8.
Now, using two’s complement notation with 4 bits, we can represent 24=16 different numbers
that range from -8 till +7 (-8 till -1 are the negative numbers and 0 till +7 are the positive
numbers)
Example 1:
(-5)10
Example 2:
(-14)10
Example 1:
(1011)2=(-5)10
Example 1:
(11110010)2=(-14)10
ASCII can represent characters for only the English language. Relying on ASCII alone made exchanging
information from different languages quite impossible.
Unicode is another way to represent characters. It uses 16 bits for each characters. With Unicode,
computer systems are able to represent characters from all human languages using a single very large
table, making exchanging information from different languages much easier nowadays
With ASCII, we will write 8 bits for every character, keeping the leftmost bit 0.
If you are given the ASCII code for a character, you can generate the equivalent ASCII code for any other
character as long as you know the relationship between the 2 characters
Example
Given that “c” is (099)10, find the ASCII code for “E”
1. c=(099)10=(01100011)2
2. e=c+2
3. e=(99+2)10=(101)10=(01100101)2. It is best to convert the binary representation to decimal and
do the calculation (addition or subtraction) in decimal, then convert the obtained decimal
number to binary
1. Having obtained the representation of “e” in binary, write the binary representation of “E”. by
changing the 3 leftmost bits from 011 to 010: E=(01000101)2
2. Convert the binary representation of E to decimal: E=(01000101)2=(69)10