The Hexadecimal NumberSystem and Memory
Addressing
ISAT 121
2
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
3
Characteristics of Numbering Systems
1) The digits are consecutive.2) The number of digits is equal to the
size of the base.3) Zero is always the first digit.4) The base number is never a digit.5) When 1 is added to the largest digit,
a sum of zero and a carry of one results.
6) Numeric values determined by the have implicit positional values of the digits.
4
Significant Digits
Binary: 11101101
Most significant digit Least significant digit
Hexadecimal: 1D63A7A
Most significant digit Least significant digit
5
History
Necessity for understanding numbering systems
Historical numbering systems in computing Decimal On/Off Binary (Ada)
Bits & bytes ASCII
6
Common terminology
Term DefinitionBit 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.
7
Common terminology
Term DefinitionGigabyte 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).
8
Example
/ 230 =
In the lab…1. Double click on My Computer2. Right click on C:3. Click on Properties
9
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
10
Decimal Number Example
Number: 1946 n = 4 and n – 1 = 3 Positions
1 * 103 = 1000 9 * 102 = 900 4 * 101 = 40 6 * 100 = 6
Sum: 1946
11
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
12
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]
13
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 = 160[10]
8 * 160 = 8[10]
Sum: 168[10]
14
Notation for Number Systems
Subscript used to denote base 25[10] decimal 19[16] hexadecimal 0001 1001[2] binary
Web pages and some programming languages Decimal: no additional symbols Hexadecimal: use pound sign “#”
Other notation conventions Hexadecimal: “h” or 0x Octal: “o” Binary: “b”
15
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
16
Conversion to Hexadecimal
Binary to hex: Convert each nibble to hex digit (see previous slide)
Decimal 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[10] to hex: (1946\256 = 7) + (154\16 = 9) + (10\1) = A Sum: 79A (7*256=1792) + (9*16=144) + (10*1=10) =
1946 Or… Windows Calculator
17
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
18
Binary Integer Addition
Binary has only two digits: 0, 1 Addition rules:
0 + 0 = 0 1 + 0 = 10 + 1 = 1 1 + 1 = 10
Examples: 3 + 3 = 0011 + 0011 = 0110 5 + 7 = 0101 + 0111 = 1100 9 + 7 = 1001 + 0111 = 10000 –
Overflow
19
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
20
Two’s Complement
Rule for storing signed integersRule for storing signed integers Results in “clock” of numbers Rule for negating a number
Take complement of number Value 6[10] = 0110[2] Complement 1001
Add one 1 Yields 2’s complement 1010
“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
01
2
3
5
6
4
-87
-1-2
-3
-4
-5
-6
-7
0123
56
4
8 7
151413
121110
9
21
Overflow and Underflow
Overflow caused by operation generating number greater than register can hold 0111 + 0001 = 1000 7 + 1 ≠ -8
Underflow caused by operation generating number less than register can hold 1000 – 0001 = 0111 -8 – 1 ≠ 7
Either will cause returned value to wrap around “clock”
22
Example
Colors on web pages are often expressed in hex “#00FF80”
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 Red: 0 Green: 100 Blue: 50
To blend a graphic into the background of a web page, the correct hex value must be calculated
23
Conclusion
Questions?