Numbering Systems

advertisement
The Hexadecimal Number
System and Memory Addressing
ISAT 121
Familiar Number Systems



Roman numerals
None, one, few, many
Positional value systems
Each position in a number has a value
 Includes concept of zero
 Example: decimal system

2
Characteristics of Numbering Systems
1)
2)
3)
4)
5)
6)
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 have implicit
positional values of the digits.
3
Significant Digits
Binary: 11101101
Most significant digit
Least significant digit
Hexadecimal: 1D63A7A
Most significant digit
Least significant digit
4
History


Necessity for understanding numbering
systems
Historical numbering systems in computing
Decimal
 On/Off
 Binary (Ada)



Bits & bytes
ASCII
5
Common terminology
Term
Definition
Bit
A numeral in the binary number system: a 0 or a 1.
Byte
8 bits (the smallest addressable memory location).
Kilobyte
1024 bytes, which is 2 to the 10th power, often rounded to
1000 bytes.
Megabyte
Either 1024 kilobytes or 1000 kilobytes, depending on what
has come to be standard practice in different situations. For
example, when calculating floppy disk capacities, 1
megabyte = 1000 kilobytes; when calculating hard drive
capacity, traditionally, 1 megabyte = 1024 kilobytes.
6
Common terminology
Term
Definition
Gigabyte
1000 megabytes or 1024 megabytes, depending on what has
come to be standard practice in different situations.
ASCII
American Standard Code for Information Interchange
coding scheme used for microcomputers, which assigns a
7- or 8-bit code to all characters and symbols. See Appendix
B for more information.
Hex
Short for hexadecimal. A number system based on 16 values
(called base 16), which is explained in this appendix. Uses
the 16 numerals 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F.
Hex numbers are often followed by a lowercase h to
indicate they are in hex (example: 78h).
7
Example
In the lab…
1. Double click on My Computer
2. Right click on C:
3. Click on Properties
/ 230 =
8
Decimal Number System


Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Base
Ten
 Each position is power of 10


Value = Σ i=0..n-1 di * 10i,
n is count of digits in number
9
Decimal Number Example



Number: 1946
n = 4 and n – 1 = 3
Positions
1 * 103 =
 9 * 102 =
 4 * 101 =
 6 * 100 =


Sum:
1000
900
40
6
1946
10
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
11
Binary Number System


Digits: 0, 1
Base:
Two
 Each position is power of 2


Example: 1010 1000[2]
1*27 + 0*26 + 1*25 + 0*24 + 1*23 + 0*22 + 0*21 +
0*20
 128[10] + 0 + 32[10] + 0 + 8[10] + 0 + 0 + 0
 Sum: 168[10]

12
Hexadecimal (Hex) Number
System


Digits: 0..9, A, B, C, D, E, F
Base:
Sixteen
 Each position is power of 16


Example: A8[16]
A * 161 =
 8 * 160 =
 Sum:

160[10]
8[10]
168[10]
13
Notation for Number Systems

Subscript used to denote base




decimal
hexadecimal
binary
Web pages and some programming languages



25[10]
19[16]
0001 1001[2]
Decimal: no additional symbols
Hexadecimal: use pound sign “#”
Other notation conventions



Hexadecimal: “h” or 0x
Octal: “o”
Binary: “b”
14
Binary to Hexadecimal Conversion


The easiest method for converting binary to
hexadecimal is to use a substitution code
Each hex digit converts to 4 binary digits
15
Conversion to Hexadecimal


Binary to hex: Convert each nibble to hex digit (see
previous slide)
Decimal to hex:



1946[10] to hex:




Use repeated division by powers of 16 to find hex digit at
each position
163 = 4096, 162 = 256, 161 = 16, 160 = 1
(1946\256 = 7) + (154\16 = 9) + (10\1) = A
Sum: 79A
(7*256=1792) + (9*16=144) + (10*1=10) = 1946
Or… Windows Calculator
16
Bits, Bytes, and Nibbles



Computers use 0 and 1 states to represent data and
instructions
Each stored state or pathway to transport a state is a
bit
Eight bits are a byte




Basic grouping of bits in computers
Can be represented by two hex digits
Values: 00..FF or 0..255
Half of byte is nibble (nybble)


Can be represented by one hex digit
Values: 0..F or 0..15
17
Binary Integer Addition


Binary has only two digits: 0, 1
Addition rules:
0+0=0
0+1=1

1+0=1
1 + 1 = 10
Examples:
3 + 3 = 0011 + 0011 = 0110
 5 + 7 = 0101 + 0111 = 1100
 9 + 7 = 1001 + 0111 = 10000 – Overflow

18
Binary Integer Subtraction



Two digits: 0, 1
Number of bits dependent
Rules for two bits and A≥B
00–00 = 00; 01–00 = 01; 01–01 = 00;
10–00 = 10; 10–01 = 01; 10–10 = 00;
11–00 = 11; 11–01 = 10; 11–10 = 01; 11–11 = 00

A<B governed by signed representation used
19
Two’s Complement
0
-1
Rule for storing signed integers


Results in “clock” of numbers
Rule for negating a number

Take complement of number





Value
Complement
6[10] =
Add one
Yields 2’s complement
0110[2]
1001
1
1010
-2
-3
14
13
1
15
-4 12
11
-5 10
-6
0
1
2
2
3
3
4
5
9
-7
8
-8
7
6
4
5
6
7
“Clock” values dependent on number of bits




4 bits: -8 .. 7
8 bits: -128 .. 127
32 bits: -2,147,483,648 .. 2,147,483,647
64 bits: -9,223,372,036,854,775,808 .. 9,223,372,036,854,775,807
20
Overflow and Underflow

Overflow caused by operation generating number
greater than register can hold



Underflow caused by operation generating number
less than register can hold



0111 + 0001 = 1000
7 + 1 ≠ -8
1000 – 0001 = 0111
-8 – 1 ≠ 7
Either will cause returned value to wrap around
“clock”
21
Example

Colors on web pages are often expressed in hex


Graphics editors often represent the color components in
decimal values




Red: 0
Green: 255
Blue: 128
Graphics editors may represent the color components as
percentages




“#00FF80”
Red: 0
Green: 100
Blue: 50
To blend a graphic into the background of a web page, the
correct hex value must be calculated
22
Conclusion
Questions?
23
Download