Download presentation
Presentation is loading. Please wait.
Published byMervin Garrett Modified over 6 years ago
1
ECE 103 Engineering Programming Chapter 3 Numbers
Herbert G. Mayer, PSU Status 6/20/2016 Initial content copied verbatim from ECE 103 material developed by Professor Phillip PSU ECE
2
Syllabus Binary Numbers Bitwise Operations Other Base Representations
Positive and Negative Integers Floating Point
3
Binary Numbers Bit Smallest unit of information (binary digit)
A single bit has two distinct states: 0 (logical False) 1 (logical True) A binary number consists of n bits grouped together. LSB MSB bn-1bn-2…b1b0 = bn-12n-1 + bn-22n-2 + … + b121 + b020 2
4
Table 1: Given n bits, the number of possible states = 2n
- 10 1024 20 1 2 11 2048 21 4 12 4096 22 3 8 13 8192 23 16 14 16384 24 5 32 15 32768 : 6 64 65536 30 7 128 17 131072 31 256 18 262144 9 512 19 524288 3
5
Convert from binary to its equivalent base 10 value Expand the powers of two.
Example: What is in decimal? 11102 = (123) + (122) + (121) + (020) = (18) + (14) + (12) + (01) = 1410 Convert from base 10 to its equivalent binary value Successively divide by two; keep track of remainders. Example: What is 1410 in binary? Base 10 Remainder 14 / 2 = 7 7 / 2 = 3 1 3 / 2 = 1 1 / 2 = 0 Read the remainders backwards. Hence, 1410 = 11102 4
6
Bitwise Operations 1 1 1 1 1 A B A & B A B A | B A B A ^ B A ~A
1 A B A | B 1 A B A ^ B 1 A ~A 1 Bitwise Complement Bitwise AND Bitwise OR Bitwise XOR A B A + B Carry 1 Bitwise Addition 5
7
Logic operations are done a bit at a time (unary operator) or a pair of bits at a time (binary operator). Example: ~1011 = Complement 1010 & 1100 = Bitwise AND 1010 | 1100 = Bitwise OR 1010 ^ 1100 = Bitwise XOR ■ ■ ■ ■ 6
8
Table 2: 4-bit positive integer conversion table
Other Base Representations Octal (base 8 0, …, 7) Hexadecimal (base 16 0, …, 9, A, B, C, D, E, F) Table 2: 4-bit positive integer conversion table Dec Bin Oct Hex 0000 8 1000 10 1 0001 9 1001 11 2 0010 1010 12 A 3 0011 1011 13 B 4 0100 1100 14 C 5 0101 1101 15 D 6 0110 1110 16 E 7 0111 1111 17 F 7
9
Converting from binary to its equivalent hex: 1) Separate binary value into 4-bit groups 2) Replace each group by its hex value Example: = = AC4416 Converting from hex to its equivalent binary: Replace each hex value by its 4-bit binary value. = 6B1316 = 8
10
Positive and Negative Integer Numbers
Integers are exactly representable in base 2 Table 3: 4-bit positive only values 0 to 15 If only positive integers and zero are needed, then all of the bits in the binary representation are available to express the value. Given : n bits Range: 0 to 2n – 1 Base 10 Base 2 0000 8 1000 1 0001 9 1001 2 0010 10 1010 3 0011 11 1011 4 0100 12 1100 5 0101 13 1101 6 0110 14 1110 7 0111 15 1111 9
11
Table 4: 4-bit positive and negative values -8 to +7
For negative integers, the most significant bit (MSB) of the binary value is reserved as a sign bit. Negative values are expressed as 2’s complement. Table 4: 4-bit positive and negative values -8 to +7 If both positive and negative integers are needed, the maximum positive value is reduced by a factor of two. Given : n bits Range: –2n-1 to 2n-1 – 1 Base 10 Base 2 (2's comp) 0000 -1 1111 1 0001 -2 1110 2 0010 -3 1101 3 0011 -4 1100 4 0100 -5 1011 5 0101 -6 1010 6 0110 -7 1001 7 0111 -8 1000 10
12
Floating Point Numbers
Floating point is used to express real-valued numbers. There is an implicit decimal point. Example: –634.9 Example: In scientific notation format (base 10) –6.349 × 102 mantissa sign base exponent 11
13
IEEE 754 single-precision (32-bit) standard s e1e2…e8 b1b2…b23
Binary can be used to represent floating point values, but usually only as an approximation. IEEE 754 single-precision (32-bit) standard s e1e2…e8 b1b2…b23 1 bit Sign 0→ + 1→ – 8 bits Interpreted as unsigned integer e' 23 bits Interpreted as a base 2 value defined as m' = 0.b1b2…b23 = b b22-2 +…+ b232-23 if e' ≠ 0 then FP number = (-1)s × (1 + m') × 2e'-127 if e' = 0 then FP number = (-1)s × m' × 2-126 12
14
Example: IEEE 754 single precision (32-bit)
The more bits available, the more precise the mantissa and the larger the exponent range. See: s = 0 e' = 17210 m' = = Number = (-1)s × (1 + m') × 2e'-127 = × 245 ≈ × 1013 13
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.