Professional Documents
Culture Documents
AND BINARY
NUMBERS
• Email:
riel.gomez@iacademy.edu.ph
Introduction
BASIC INFORMATION
• Absences
Introduction
BASIC INFORMATION
• The following rules will be strictly enforced during
classes:
‒ No sleeping in class.
• Analog Signal
+5v
An analog signal is a
continuous signal that 0v
can assume all possible
values (infinite) within -5v
its given range.
A discrete signal is a 0v
signal that can assume
only certain values
within its given range. -5v
A digital signal is a
discrete signal that can +5v
assume only two
possible values (binary). 0v
7245 = (7
(7××1000)
1000) + (2
(2××100)
100) + (4
(4××10)
10) ++ (5
(5××1)1)
(7×103)3) ++(2×10
= (7×10 2)2 + (4×101)1
(2×10 (5×100)0)
) + (4×10 ) + (5×10
• Other Examples:
4 3 2 1 0
79561 = 7 ××10
104 4 + 9 × 103 + 5 × 1022 + 6 × 1011++11××10
1000
2 1 0
For example:
1 0 -1 -2
= 7 ×× 10
10 ++ 22××11 ++ 44××0.1
0.1 + 55 ××0.01
0.01
= 70 + 2 + 0.4 + 0.05
Examples:
1234510 (Base
(Base10)
10)
Hexadecimal numbers
may also be written
423415 (Base 5)
(Base 5)
as:
‒ 2C4ABH
1010102 (Base 2)
(Base 2)
‒ 0x2C4AB
Examples:
3 2 1 0
• Exercises
34215
101010.012
D4B16
734.268
• Since computers can only understand 0s and 1s, the binary number system is
the commonly used number system in the field of computing. So numbers are
expressed in terms of powers of two:
n 2n n 2n
0 1 11 2,048
1 2 12 4,096
2 4 13 8,192
3 8 14 16,384
4 16 15 32,768
5 32 16 65,536
6 64 17 131,072
7 128 18 262,144
8 256 19 524,288
9 512 20 1,048,576
10 1,024 21 2,097,152
Example:
4 3 2 1 0
110112= 1 × 244 ++11××2323+ 0+ ×0 2×2 2+2 1 ×+ 211×+211 × +201 × 20
= 1 × 16 + 1 × 8 + 0 × 4 + 1 × 2 + 1 × 1
= 16 + 8 + 0 + 2 + 1
= 2710
Example:
128 64 32 16 8 4 2 1
1 1 0 1 0 1 1 02 = 128 + 64 + 16 + 4 + 2
= 21410
Digital Systems and Binary Numbers
CONVERTING BINARY NUMBERS TO DECIMAL
• Exercises
10112
1011102
011111012
1101.112
• There is the possibility that the repeated multiplication may not result in a
number with 0 remainder.
0.65 ×× 22 ==1.3
1.3 integer
integer ==11 MSB
0.3 ×× 22 ==0.6
0.6 integer==00
integer
0.6 ×× 22 ==1.2
1.2 integer==11
integer 0.6510 = 0.101012
0.2 ×× 22 ==0.4
0.4 integer
integer ==00
0.4 ×× 22 ==0.8
0.8 integer
integer ==00
0.8 ×× 22 ==1.6
1.6 integer==11 LSB
integer
13/2 == 66 rr 11
0.375 ×× 22 ==0.75
0.75 int
int ==00
6/2 == 3 r 00
0.75 × 22 ==1.51.5 int
int ==11
3/2 = 1 r 11
1/2 == 00 rr
0.5 × 2 ==1.0 1.0 int
int ==11
11
13.37510 == 1101
1101.011
.01122
• Exercises
11110
25510
6410
386.812510
1,000 1,000
Mega = 1,000,000 = 106 == 1,000 1,000
1,000 1,000
Giga = 1,000,000,000 = 109 == 1,000 1,000 1,000
1,000
Example: 4 KB = 4 1,000
1,024 = 5,000
4,096 grams
bytes
Mega = 1,000,000
1,048,576 = 10 1,024 1,000
2206 == 1,000 1,024
Example: 8 MB = 8 1,048,000
1,048,576 == 8,000,000
8,388,608volts
bytes
Giga = 1,000,000,000
1,073,741,824 = 10 1,024 1,000
2309 == 1,000 1,024 1,000
1,024
Example: 16 GB ==916 1,073,741,824
1,000,000,000 = 9,000,000,000 watts
= 17,179,869,184 bytes
1518/8== 189
189 remainder
remainder 66 LSD
189/8 = 2323 remainder
remainder 55
151810 = 27568
23/8 = 22 remainder
remainder 77
2/8 = 00 remainder
remainder 22 MSD
0.513 × 8 ==4.104
4.104 integer
integer ==44 MSD
0.104 ×× 8 ==0.832
0.832 integer
integer ==00
0.51310 = 0.4078
0.832 ×× 8 ==6.656
6.656 integer = 6
integer = 6
0.656 ×× 8 ==5.248
5.248 integer ==55 LSD
integer
• Exercises
8310
304110
826.70117187510
4789/16 = 299
299 remainder
remainder 5 LSD
299/16 = 1818 remainder
remainder 11
11 478910 = 12B516
18/16 = 11 remainder
remainder 2
1/16 = 00 remainder
remainder 1 MSD
B
Digital Systems and Binary Numbers
CONVERTING DECIMAL NUMBERS TO HEXADECIMAL
• Exercises
29110
1498010
2903.67187510
4 7 2 3
47238 = 1001110100112
10101101112 = 12678
4 A E 9
4AE916 = 01001010111010012
10 1011 0111
2 B 7
10101101112 = 2B716
100111010011 9D3
47238 = 9D316
Digital Systems and Binary Numbers
OCTAL AND HEXADECIMAL NUMBER SYSTEMS
• And more often than not, binary numbers are written using a fixed number of
bits.
Examples:
Range: 0 to 2n – 1
Examples:
to2244––1.1. (0
1. If n = 4 bits, then the range is 0 to (0to
to15)
15)
to 2255––1.1. (0
2. If n = 5 bits, then the range is 0 to (0 to
to31)
31)
to 2288––1.1. (0
3. If n = 8 bits, then the range is 0 to (0 to
to255)
255)
This is because modern computer systems use 4 bytes (32 bits) to represent such
a value.
With 32 bits, the range of numbers that can be represented by an unsigned int
variable will be:
Range: 0 to 2n – 1
0 to 232 – 1
0 to 4,294,967,295
log 𝑁
𝑛=
log 2
Example:
log 26
𝑛= == 4.7 bits 55 bits
4.7bits bits
log 2
00110110 = + 5410
+
54 In unsigned numbers,
00110110 would be 5410.
10010110 == –– 22
2210
–
22 In unsigned numbers,
10010110 would be 15010.
• Examples:
Convert +2710 to a binary number using the sign and
magnitude representation:
2710 = 11011
110112 2 (unsigned)
+2710 = 011011
0 2 (add a 0 to its leftmost bit position)
2710 = 11011
110112 2 (unsigned)
• Examples:
Convert +2710 to a 7-bit binary number using the sign and
magnitude representation:
2710 = 11011
110112 2 (unsigned)
+2710 = 0011011
00 2 (add two 0s to make it 7 bits)
• Exercises
–11010
–25610
–6410
+18210
• Exercises
–11010
–25610
–3510
+2710
– 0111012 = 2910
10111012 = –2910
Digital Systems and Binary Numbers
SIGNED BINARY CODES (SIGN AND MAGNITUDE)
• Exercises
1110112
0101012
101010002
10101112
8710 = 1010111
10101112 2 (unsigned)
• The range of values that can be represented with n bits using sign
and magnitude binary code is given by the following equation:
Examples:
–(233––1)1)toto
1. If n = 4 bits, the range is –(2 +(2+(2 3 – 1). (–7
3 – 1). (–7toto+7)
+7)
–(266––1)1)toto
2. If n = 7 bits, the range is –(2 +(2+(2 6 – 1). (–63
6 – 1). (–64toto+63)
+64)
–(277––1)1)toto
3. If n = 8 bits, the range is –(2 +(2+(2 7 – 1). (–127
7 – 1). (–128toto+127)
+128)
• 1's Complement
• Examples:
Convert +2710 to a binary number using the 1's complement
representation:
2710 = 11011
110112 2 (unsigned)
+2710 = 011011
0 2 (add a 0 to its leftmost position)
–2710 = 1100100
0 0 1 0 0 2 (complement each bit)
• Examples:
Convert +2710 to a 7-bit binary number using the 1's
complement representation:
2710 = 11011
11011
2 2 (unsigned)
+2710 = 00
00110112 (add two 0s to its leftmost position)
–2710 = 11100100
1 0 0 1 0 0 2 (complement each bit)
• Exercises
+6510
–3410
–13210
+2910
• Exercises
+6510
–3410
–13210
+2910
0011101
+ 00111012 = 2910
00111012 = +2910
Digital Systems and Binary Numbers
SIGNED BINARY CODES (1'S COMPLEMENT)
1011101
– 01000102 = 3410
0100010
10111012 = –3410
Digital Systems and Binary Numbers
SIGNED BINARY CODES (1'S COMPLEMENT)
• Exercises
111111112
101010112
001010102
1111001112
• The range of values that can be represented with n bits using 1's
complement binary code is given by the following equation:
Examples:
–(233––1)1)toto
1. If n = 4 bits, the range is –(2 +(2+(2 3 – 1). (–7
3 – 1). (–7toto+7)
+7)
–(266––1)1)toto
2. If n = 7 bits, the range is –(2 +(2+(2 6 – 1). (–63
6 – 1). (–64toto+63)
+64)
–(277––1)1)toto
3. If n = 8 bits, the range is –(2 +(2+(2 7 – 1). (–127
7 – 1). (–128toto+127)
+128)
• 2's Complement
• Examples:
Convert +2710 to a binary number using the 2's complement representation:
001012
–2710 = 1100101
–2710 = 11100101
10 01012
• Exercises
+6510
–3410
–13210
+2910
• Exercises
+6510
–3410
–13210
+2910
0011101
+ 00111012 = 2910
00111012 = +2910
Digital Systems and Binary Numbers
SIGNED BINARY CODES (1'S COMPLEMENT)
10111012 = –3510
Digital Systems and Binary Numbers
SIGNED BINARY CODES (2'S COMPLEMENT)
• Exercises
111111112
101010112
001010102
111001112
• The range of values that can be represented with n bits using 2's
complement binary code is given by the following equation:
–(2n-1n-1) ) to
Range: –(2 +(2n-1n-1––1)1)
to +(2
Examples:
–(233) )toto+(2
1. If n = 4 bits, the range is –(2 3 –31).
+(2 – 1). (–8
(–8toto+7)
+7)
–(266))toto+(2
2. If n = 7 bits, the range is –(2 6 –61).
+(2 – 1). (–64
(–64 toto+63)
+63)
–(277))toto+(2
3. If n = 8 bits, the range is –(2 7 –71).
+(2 – 1). (–128
(–128 toto+127)
+127)
In C++, an int variable (which is actually a signed int variable following 2’s
complement) represents a number between -2,147,483,648 to +2,147,483,647.
With 32 bits, the range of numbers that can be represented by a signed int
variable will be:
–(232-1) to +(232-1 – 1)
–2,147,483,648 to +2,147,483,647
#include <iostream>
using namespace std;
• Exercises
111111112
101010112
001010102
111001112
Memory
1. input,
Output Control
2. memory,
3. arithmetic and logic,
I/O Processor
4. output,
5. and control units.
0 1 0 1
+ 0 + 0 + 1 + 1
0 1 1 10
0
Carry-out
+810 = 010002
+ +710 = 001112
011112 = 1510
01111
Digital Systems and Binary Numbers
BINARY ARITHMETIC
+1010 = 010102
+ – 610 = 110102
1100100
0 0100 2
The carry out
of the sign
bit is ignored 001002 = +410
• Exercises
7510 + 2810
–7010 – 5010
3510 – 5410
–4810 + 5110
+810 = 010002
+ +910 = 010012
10 0012 = –1510
10001
Digital Systems and Binary Numbers
OVERFLOW
–7010 = 101110102
+ –7510 = 101101012
ignore 101101111
10110 11112 = +11110
• Exercises
3410 – 1510
–7110 – 5710
3510 + 9910
–4810 + –2710