1 data representation characters, integers and real numbers binary number system octal number system...
TRANSCRIPT
1
Data Representation
Characters, Integers and Real Numbers Binary Number System Octal Number System Hexadecimal Number System
Powered by DeSiaMore
2
Data Representation
Binary Representation Only two things, need only 1 bit Want to represent Sweet and Sour
1 for Sweet 0 for Sour
Want to represent more than 2 things Need more bits
For 4 things, like 4 colors need 2 bits 00 - blue yellow - 10 01 - red black - 11
Powered by DeSiaMore
3
Data Representation
Binary Representation If you have
More than 4 things need more than 2 bits 8 things, need 3 bits 16 things, need 4 bits 32 things, need 5 bits
In general, if you want to represent 2n things need n bits
Binary means each time we add a bit, we double the things we can represent
Powered by DeSiaMore
4
Data Representation
Representing Numbers Integer - is a whole number, 0, 1, 2, 3, 4 … n To store integers in the computer, we only need the
number of bits for the magnitude of the number So, for integers up to 256 which = 28
we need 8 bits Higher integers will require more bits
9 bits can store integers up to 512 10 bits can store integers up to 1024
Powered by DeSiaMore
5
Representing Numbers
For integers `always include 0 Zero takes up one of our choices
Means we can actually store numbers up to 255 in bits
Binary Decimal
0000 0000 0
0000 0001 1
0000 0010 2
0000 0011 3
0000 0100 4 …
1111 1111 255 Maximum in bits
+ 1 Add 1
10000 0000 256
Powered by DeSiaMore
6
Representing Numbers Real Numbers or “Floating Point”
More complicated to store real numbers Will have a value and a fractional part Example:
104.3 -35.21
3.5346 0.999
10000.98 8.6547 Numbers that have decimal points are real numbers
Powered by DeSiaMore
7
Representing Numbers Real Numbers
Example: 3 2 7 5 . 6 1 2 103 102 101 100 10-1 10-2 10-3
To the left of decimal point: 1’s,10’s,100’s,1000’s To the right of point: 10th’s, 100th’s, 1000th’s The decimal point has a special name it’s called the
Radix point Inside the computer we store the value as an integer
and then include information about Radix Point
Radix Point
Powered by DeSiaMore
8
Representing Numbers Real Numbers
Composed of three parts
1. Sign + or -
2. Mantissa - the number value
3. Exponent - tells how the radix point gets moved Example: 148.69
Sign: + Exponent: -2 Mantissa: 14869
Powered by DeSiaMore
9
Representing Numbers Real Numbers
More Examples: -2345.1 Sign: - Exponent: -1 Mantissa: 23451
Example: 677.00 Sign: + Exponent: 0 Mantissa: 677
Powered by DeSiaMore
10
Representing Numbers Real Numbers
Equation for defining a real number:
Sign * mantissa * 10exponent
Decimal point “floats” according to the exponent
Examples using the above equation
(assume 5 digits per number):12001.00 +12001 X 100
-520.05 -52005 X 10-2
0.62200 +62200 X 10-5
21.998 +21998 X 10-3
Powered by DeSiaMore
11
Representing Numbers Real Numbers
When storing a real number, PC uses 64 bits 1 bit for the sign 11 bits for the exponent 52 bits for the mantissa
Powered by DeSiaMore
12
Representing Characters Storing Characters
A text document that you type in a word processor is decomposed into paragraphs, sentences and words
Individual characters are actually stored in the computer
Powered by DeSiaMore
13
Representing Characters To represent a document
Must represent every character How do you do this?
Documents are in a given language In any language there are a finite number of characters Want to list each character and assign it a unique binary
string or pattern
Powered by DeSiaMore
14
Representing Characters English - How many characters?
26 - Upper case letters 26 - Lower case letter 0 - digits Punctuation characters Non-printing control codes The number of unique things determines the number of bits
needed
Powered by DeSiaMore
15
Representing Characters Computer manufacturers found it easier to standardize
the way characters are represented Recall: ASCII, EBCDIC and Unicode
ASCII - Allows for 256 characters That means can represent 256 different characters How many bits then per character?
Powered by DeSiaMore
16
Representing Characters
ASCII Needs bits to represent all the characters Charts are printed in different ways
Hex, binary and decimal Easiest to read in decimal
However, numbers are stored in binary in the computer
Note: ASCII codes are in order Means can sort characters and numbers A, B, C, D, E, F, … a, b, c, d, e, f, … 1, 2, 3, 4, 5, ….
Powered by DeSiaMore
17
ASCII
Codes
Powered by DeSiaMore
18
Representing Characters ASCII
First 32 characters are non-printing ESC key, Backspace key, Tab, Enter key plus others
ASCII is ok for English, but what about other languages? Like Chinese?
Chinese has many more characters far greater than 256
Powered by DeSiaMore
19
Representing Characters Unicode
Goal of the Unicode representation is to create a character set that can represent every language used in the world
Unicode is a large extension of the ASCII character set Comparison between ASCII and UnicodeUnicode ASCII 16 bits/character 8 bits/character65,000 characters 256 charactersSuperset of ASCII
Powered by DeSiaMore
20
Representing Characters Unicode
Superset of ASCII ASCII takes up the first 256 characters of Unicode
Still evolving, currently 40,000 characters have been encoded!
Powered by DeSiaMore
21
Number Systems
Powered by DeSiaMore
22
Number Systems All number systems have a base or radix Decimal system – the base is 10 Different number systems have different bases
Binary the base = 2 Time the base = 60
Base affects counting Counting in Decimal – ranges from 0 - Counting in base 60 – ranges from 0 - 59
Powered by DeSiaMore
23
Number Systems Number systems are positional Know how big the number is from its position in the
number Example: 943
You know that 9=900, 4 = 40, 3 = 3
Powered by DeSiaMore
24
Number Systems
Positional Notation A more structured way to say this:
Rightmost digit = value x base0 power Next digit to the left = value x base1 power Next digit to the left = value x base2 power …..
Example: 943 base 109 X 102 = 9 X 100 = 9004 X 101 = 4 X 10 = 40 +3 X 100 = 3 X 1 = 3 943
We will extend this concept to the other number systems:Octal and Hexadecimal
Powered by DeSiaMore
25
Computer Number Systems Actually 3 number systems used for computers
Binary - base 2 Octal – base 8 Hexadecimal - base 16
Digits in each system Binary: 0,1 Octal: 0 - 7 Hexadecimal - 0 -, and A,B,C,D,E,F
A = 10, B=11, C=12, D=13, E=14, F=15
Powered by DeSiaMore
26
Computer Number Systems Why other number systems?
Binary numbers are hard to read – ok for computers Even small numbers need lots of digits Example:
Decimal number = 14 Binary number = 1110
Other number systems are for people Makes it easier to read and work with digital numbers
Powered by DeSiaMore
27
Binary Number Chart
Powered by DeSiaMore
28
Computer Number Systems Why other number systems?
Turns out that Octal and Hexadecimal make it easy to convert between
the different number systems Binary to Octal, Hexadecimal Octal, Hexadecimal to Decimal
Powered by DeSiaMore
29
Number System Conversions
Binary Number System and Decimal Decimal and Binary Binary and Octal and hexadecimal Binary Arithmetic
Powered by DeSiaMore
30
Converting Between Number Systems
Useful to convert between number systems People more familiar with decimal numbers Should know how to do this even if you always use a
calculator to do the conversion Binary to octal, hex or decimal Decimal to binary Octal or hex to decimal
Powered by DeSiaMore
31
Converting Between Number Systems Example: Binary to Decimal
1 0 1 1
23 22 21 20
1 x 23 = 1 x 8 = 8
0 x 22 = 0 x 4 = 0
1 x 21 = 1 x 2 = 2
1 x 20 = 1 x 1 = + 1
11
Powered by DeSiaMore
32
Converting Between Number Systems Octal Conversion
3 2 18
210
3 x 82 = 3 x 64 = 1922 x 81 = 2 x 8 = 16 +
1 x 80 = 1 x 1 = 1
20910
Powered by DeSiaMore
33
Number Systems Converting Between Number Systems
Octal Conversion
2 3 3 18
3210
2 x 83 = 2 x 512 = 1024
3 x 82 = 3 x 64 = 192 +
3 x 81 = 3 x 8 = 24
1 x 80 = 1 x 1 = 1
124110
Powered by DeSiaMore
34
Number Systems Converting Between Number Systems
Hexadecimal Conversion
A B C16
162 161 160
A x 162 = 10 x 256 = 2560B x 161 = 11 x 16 = 176 +C x 160 = 12 x 1 = 1
274810
Powered by DeSiaMore
35
Number Systems Converting Between Number Systems
Binary to decimal Number is large, takes a long time Shortcut:
Convert from binary to octal (or hex) Convert from octal (or hex) to decimal
Powered by DeSiaMore
36
Number Systems
Converting Between Number Systems Convert a binary number to Octal - Easy
111101100 = 482 in decimal
1. Break up the number into groups of three starting at the right
2. Each group of three forms a binary number
3. For each digit - you only need to know binary numbers up through 7
4. Memorize or look up on a chart
Powered by DeSiaMore
37
Converting from Binary
to Octal
Example: 111|101|100100 = 4101 = 5111 = 7
754 octal
Example: 1|010|110
110 = 6
010 = 2
001 = 1
126 octal
Powered by DeSiaMore
38
Convert from Octal to Decimal 754 octal
7 x 82 = 7 x 64 = 448
5 x 81 = 5 x 8 = 40
4 x 80 = 4 x 1 = 4
48210
126 octal
1 x 82 = 1 x 64 = 64
2 x 81 = 2 x 8 = 16
6 x 80 = 6 x 1 = 6
8610
Powered by DeSiaMore
39
Converting from Binary to Hex1. Starting from the rightmost digit, group into 4 instead of
3, convert each group of 4 into a hex digit
2. Example: 1010110 0110 = 6
0101 = 5
3. Now convert to decimal as before5 x 161 = 5 x 16 = 80
6 x 160 = 6 x 1 = 6
8610
Powered by DeSiaMore
40
Converting Decimal to Other Base Systems Rules for converting decimals involve division Divide the decimal by the other base
Example: Convert to binary, divide by 2 Get a quotient and a remainder Remainder becomes the new digit in the number Quotient replaces the original number Do this until quotient = 0
Powered by DeSiaMore
41
Converting Decimal to Other Base Systems Algorithm for Converting Decimal to other Base
Systems While quotient is not zero
Divide decimal number by new base Make remainder the next digit to the left in the answer Replace decimal number with the quotient
Powered by DeSiaMore
42
Converting Decimal to Other Base Systems Decimal to Binary
Example: 45 decimal
45 / 2 = 22 quotient with 1 remainder
22/ 2 = 11 quotient with 0 remainder
11/2 = 5 quotient with 1 remainder
5/2 = 2 quotient with 1 remainder
2/2 = 1 quotient with 0 remainder
1/2 = 0 quotient with 1 remainder
Final answer: 101101 binary
Powered by DeSiaMore
43
Converting Decimal to Other Base
Systems
Decimal to octal Example: 321 decimal
321/8 = 40 is quotient and 1 is remainder
40/8 = 5 is quotient and 0 is remainder
5/8 = 0 is quotient and 5 is remainder
Final Answer: 501 octal
Powered by DeSiaMore
44
Converting Decimal to Other Base
Systems
Decimal to hex Example: 43 decimal
43/16 = 2 is quotient and 11 is remainder, 11=B in hex
2/16 = 0 is quotient and 2 is remainder
Final answer: 2B in hex
Powered by DeSiaMore
45
Binary Arithmetic Similar to decimal - same rules, different digits Basic idea is: 0 + 1 = 1, 1 + 1 = 2, 2 + 1 = 3 until we
have 9 + 1 = what? No symbol for 10 in decimal, reuse the same digits Rely on position to tell what the meaning is Rightmost digit becomes 0 and carry 1 to next position:
9 + 1
10
Powered by DeSiaMore
46
Binary Arithmetic In Binary addition there is the same idea Run out of digits a lot sooner 0 + 1 = 1 and 1 + 1 = 0 with a carry of 1 Repeat this for a large number with multiple columns Rules of Binary Addition:
0 + 1 = 1
1 + 1 = 0 with a carry of 1
1 + 1 + 1 = 1 with a carry of 1
Powered by DeSiaMore
47
Binary Arithmetic Add two numbers Examples 10110 46 1010 10+ 11011 27 + 1111 15
101 5 1110 14
+ 101 5 + 111 7
Powered by DeSiaMore
48
Binary Arithmetic Binary Subtraction
Similar to decimal Rules for borrowing
0 - 0 = 0
1 - 1 = 0
0 - 1 = Can’t do this unless you borrow from the next column with a 1
Powered by DeSiaMore
49
Binary Arithmetic Binary Subtraction
Cross out the 1 and put a zero in its place In decimal, you reduce the number by 1 In binary, you cross out the 1 and put a zero
The 1 you borrowed becomes: 10 - 1 = 1 Why?
Powered by DeSiaMore
50
Binary Arithmetic
Binary Subtraction 10-1 = 1 because 10 is 2 in binary and 2 - 1 = 1 Examples: 1011 11 110010 50- 100 4 - 10101 21
1000 8 1001001 73
- 11 3 - 10111 23
Powered by DeSiaMore
51
Binary Arithmetic
Multiplication Rules
1 x 0 = 0 0 x 0 = 0 1 x 1 = 1
11010 26 101110 46 10101 21x 101 5 x 10 2 x 111 7------------------ ------------------- -----------------
Powered by DeSiaMore
52
Converting Numbers with Fractions
Powered by DeSiaMore
53
Signed Numbers
Powered by DeSiaMore
54
BCD
Powered by DeSiaMore