Download presentation
Presentation is loading. Please wait.
1
Number Systems & Binary Arithmetic
Slides adapted from: Dr. Wood, Univ. of Maryland Prof. Orr, Indiana Univ.
2
Encoding Information We use encoding schemes to represent and store information. • Roman Numerals: I, IV, XL, MMIV • Acronyms: UMW, CPSC-125, SSGN-726 • Postal codes: 22401, M5W 1E6 Encoding schemes are only useful if the stored information can be retrieved.
3
Introduction to Numbering Systems
We are all familiar with the decimal number system (Base 10). Some other number systems that we will work with are: Binary Base 2 Octal Base 8 Hexadecimal Base 16
4
Characteristics of Numbering Systems
The digits are consecutive. The number of digits is equal to the size of the base. Zero is always the first digit. The base number is never a digit. When 1 is added to the largest digit, a sum of zero and a carry of one results. Numeric values determined by the number have implicit positional values of the digits.
5
Decimal Notation base 10 or radix uses 10 symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 • Position represents powers of 10 • or 5473 (5 * 103) + (4 * 102) + (7 * 101) + (3 * 100) • or (7 * 101) + (3 * 100) + (1 * 10-1) + (9 * 10-2)
6
Why we use a Decimal Number System
7
Binary Notation Binary Notation • base uses only 2 symbols 0, 1 • Position represents powers of 2 • (1 * 24) + (1 * 23) + (0 * 22) + (1 * 21) + (0 * 20) • (1 * 21) + (0 * 20) + (1 * 2-1) + (1 * 2-2)
8
Binary Number System Also called the “Base 2 system”
The binary number system is used to model the series of electrical signals computers use to represent information 0 represents the no voltage or an off state 1 represents the presence of voltage or an on state
9
Why do we need the Binary System?
“On” 1 True “Off” 0 False
10
Octal Notation base uses 8 symbols 0, 1, 2, 3, 4, 5, 6, 7 • Position represents power of 8 • (1 * 83) + (5 * 82) + (2 * 81) + (3 * 80) • (5 * 81) + (6 * 80) + (7 * 8-1) + (2 * 8-2)
11
Hexadecimal Notation base 16 or ‘hex’ ... uses 16 symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F • Position represents powers of 16 • B65F16 or 0xB65F (11 * 163) + (6 * 162) + (5 * 161) + (15 * 160) • F3.A916 or 0xF3.A9 (15 * 161) + (3 * 160) + (10 * 16-1) + (9 * 16-2)
12
Why do we need Hex and Octal ?
• Humans are accustomed to decimal • Computers use binary • So why ever use octal or hexadecimal? Binary numbers can be long with a lot of digits Longer number make for more confusion Copying longer numbers allows greater chance for error Octal represents binary in 1/3 the number of digits Hexadecimal represents binary in 1/4 the number of digits
13
Conversions Binary , Octal , Hex to Decimal
Decimal to Binary , Octal , Hex Binary to Octal , Octal to Binary Binary to Hex , Hex to Binary
14
Base B to Decimal (Base 10)
The easiest method for converting a number in base B to its decimal equivalent is to use the Multiplication Algorithm Multiply the binary digits by increasing powers of B, starting from the right Then, to find the decimal number equivalent, sum those products
15
Binary to Decimal Example
Convert ( )2 to its decimal equivalent: Binary Positional Values x x x x x x x x 27 26 25 24 23 22 21 20 Products 17310
16
Octal to Decimal Example
Convert 6538 to its decimal equivalent: Octal Digits x x x Positional Values Products 42710
17
Hex to Decimal Example Convert 3B4F16 to its decimal equivalent: Hex Digits 3 B F x x x x Positional Values Products 15,18310
18
Decimal (Base 10) to Base B
The easiest way to convert a decimal number to its base B equivalent is to use the Division Algorithm This method repeatedly divides a decimal number by B and records the quotient and remainder The remainder digits form the Base B equivalent in least significant to most significant digit sequence
19
Decimal to Binary Example
Convert 67 to its binary equivalent: 6710 = x2 Step 1: 67 / 2 = 33 R Divide 67 by 2. Record quotient in next row Step 2: 33 / 2 = 16 R Again divide by 2; record quotient in next row Step 3: 16 / 2 = 8 R Repeat again Step 4: 8 / 2 = 4 R Repeat again Step 5: 4 / 2 = 2 R Repeat again Step 6: 2 / 2 = 1 R Repeat again Step 7: 1 / 2 = 0 R 1 STOP when quotient equals 0
20
Decimal to Octal Example
Convert to its octal equivalent: 427 / 8 = 53 R3 Divide by 8; R is LSD 53 / 8 = 6 R5 Divide Q by 8; R is next digit 6 / 8 = 0 R Repeat until Q = 0 6538
21
Decimal to Hex Example 33E16
Convert to its hexadecimal equivalent: 830 / 16 = 51 R14 51 / 16 = 3 R3 3 / 16 = 0 R3 = E in Hex 33E16
22
Binary to Octal Example
Binary to Octal – Group in 3’s • • (12) (1002) (1102) (1112) • (18) (48) (68) (78) • 14678
23
Octal to Binary Example
Octal to Binary – Write each octal digit as a 3 bit binary equivalent • 14678 • (18) (48) (68) (78) • (0012) (1002) (1102) (1112) •
24
Binary to Hex Example Binary to Hex – Group in 4’s • • (10112) (01102) (01012) (11112) • (B16) (616) (516) (F16) • B65F16
25
Hex to Binary Example Hex to Binary – write each hex digit as a 4 bit binary equivalent • B65F16 • (B16) (616) (516) (F16) • (10112) (01102) (01012) (11112) •
26
Computing Systems • Computers were originally designed for the primary purpose of doing numerical calculations. Abacus, counting machines, calculators • We still do numerical operations, but not necessarily as a primary function. • Computers are now “information processors” and manipulate primarily nonnumeric data. Text, GUIs, sounds, information structures, pointers to data addresses, device drivers
27
Codes • A code is a scheme for representing information.
• Computers use codes to store types of • Examples of codes: Alphabet DNA (biological coding scheme) Musical Score Mathematical Equations
28
Codes • Two Elements (always) 1) A group of symbols 2) A set of rules for interpreting these symbols • Place-Value System (common) - Information varies based on location - Notes of a musical staff - Bits in a binary number
29
Computers and Codes Computers are built from two-state electronics. • Each memory location (electrical, magnetic, optic) has two states (On or Off) • Computers must represent all information using only two symbols • On (1) • Off (0) • Computers rely on binary coding schemes
30
Computers and Binary • Decimal 109 • Binary • Computer 16-bit word size • Computer 32-bit word size bit words are now common
31
zeroes are frequently dropped.
Binary Addition 4 Possible Binary Addition Combinations: (1) (2) 0 (3) (4) 1 Note that leading zeroes are frequently dropped. Carry Sum
32
Negative Numbers 4 ways to represent negative numbers
Sign Magnitude Format One’s Complement Format Two’s Complement Format Excess – N Format We study the first 3 here
33
Sign Magnitude format Sign-Magnitude Format • Uses the highest order bit as a ‘sign’ bit. All other bits are used to store the absolute value (magnitude) • Negative numbers have the sign bit set • in 16-bit representation using a sign bit
34
Consequences of Sign Magnitude
Two ways to represent 0 +0 = -0 = Reduces the range of values that can be stored.
35
One’s Complement One’s Complement Format • Exact opposite of the sequence for the positive value. Each bit is “complemented” or “flipped” • 109 in 16-bit representation • -109 in 16-bit One’s Complement
36
Consequences of One’s Complement
Two ways to represent 0 +0 = -0 = • This makes mathematical operations difficult
37
Two’s Complement Two’s Complement Format • Add 1 to One’s Complement • 109 in 16-bit representation • -109 in 16-bit One’s Complement • -109 in 16-bit Two’s Complement
38
Consequences of Two’s Complement
In two's-complement, there is only one zero ( ) Mathematical operations are much simpler
39
Next Time : Programming Languages
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.