Abstraction – Number Systems and Data Representation
-
Upload
sophia-rosales -
Category
Documents
-
view
15 -
download
0
description
Transcript of Abstraction – Number Systems and Data Representation
![Page 1: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/1.jpg)
Abstraction – Number Systems and Data Representation
![Page 2: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/2.jpg)
Memory• Computer memory is used
to store data • The smallest unit of
memory is a bit (Binary digIT)
• A bit can be off (no voltage) or on (has voltage) which we interpret to be 0 or 1
• Memory is organized into 8 bit contiguous groups called bytes. A megabyte is 1,048,576 bytes (over 1 million bytes). A gigabyte is over 1 billion bytes.
![Page 3: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/3.jpg)
How does Memory Represent Values?
• The different patterns of the on and off bits in a byte determine the value stored
• Numbers are stored using binary numbers– 101 is 1 * 20 + 0 * 21 + 1 * 22 = 5
• Characters are internally represented as numbers– Different numbers represent different characters– There are several systems for assigning numbers to
characters: • ASCII, EBCDIC, and Unicode
![Page 4: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/4.jpg)
Encodings Make Computers Powerful
• Voltages are interpreted as numbers• Numbers can be interpreted as characters• Characters can be interpreted to be part of a
link to Sun’s Java Site
0100 0001
off on off off off off off on
a
<a href=http://java.sun.com>Sun’s Java Site </a>
![Page 5: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/5.jpg)
Notepad Exercise• Open notepad and type a
sentence in it• Save the file• Check the size in bytes by
leaving the cursor over the file name – Or right click and check
properties
• Now count the number of letters and spaces
![Page 6: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/6.jpg)
Binary Numbers
• A bit is a binary digit with a value of 0 or 1– A group of 8 bits is a byte
• Computer memory is allocated in bytes• Numbers are stored using the binary number system
– With digits of 0 or 1 and powers of 2
• Other number systems– Decimal- digits of 0 to 9 and powers of 10– Octal - digits of 0 to 7 and powers of 8– Hexadecimal – digits of 0 to 9 and A, B, C, D, E, F and
powers of 16.
05-DrawingInJava 6
![Page 7: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/7.jpg)
Converting from Binary to Decimal
• Multiply the digit value times the place value and add up the results to convert from binary to decimal
• The place values start with 20 on the right (which is 1) and increase to the left
7
![Page 8: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/8.jpg)
Converting from Decimal to Binary
• Subtraction MethodKeep subtracting out
largest power of two until nothing remains
8
![Page 9: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/9.jpg)
Converting from Decimal to Binary
• Division Method
Read result from top to bottom.
9
![Page 10: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/10.jpg)
Binary Addition
• To add two decimal numbers you add the digits and if the total is greater than ten you carry the one into the next column
• To add two binary numbers – 0 + 0 = 0– 0 + 1 and 1 + 0 = 1– 1 + 1 = 0 with a carry of 1 into the next column to the left
00 10 111 01 01 001---- --- ------ 01 11 1000 00111001010 01010101101 -------------------10001110111
![Page 11: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/11.jpg)
2’s Compliment Notation
• Computers actually only know how to add– So, how do they handle subtraction?
• Computers subtract by adding a negative number
• How do you represent a negative number in memory?– Positive numbers in 2’s compliment are just the
same as a binary number– For negative numbers reverse 0s and 1s and then
add 1
![Page 12: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/12.jpg)
2’s Compliment Example
• To subtract 3 from 7• First represent both as a binary number
– 7 is 0000 0111– 3 is 0000 0011
• Reverse the 0s and 1s and then add 1 to get -3– 0000 0011 reversed is 1111 1100– add 1 0000 0001– The result is 1111 1101
![Page 13: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/13.jpg)
Add the Negative Number
• To subtract 3 from 7• Add -3 to 7
– 7 is 0000 0111– -3 is 1111 1101– The result is 1 0000 0100
• Throw away the leftmost 1• The answer is 0000 0100 which is 4
![Page 14: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/14.jpg)
Patterns Exercise
• How many different patterns of on and off bits are there in 3 bits? How many in 4 bits? How many in 8 bits?
• 000 is one pattern• 001 is another pattern• 010 is another pattern
![Page 15: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/15.jpg)
Does the number of patterns matter?• Some garage door
openers in the 70s used 8 bits to set the code to use to open the door– Giving 256 different
patterns– Which is enough that
you won’t open your neighbors door
– But small enough that someone could try each one
![Page 16: Abstraction – Number Systems and Data Representation](https://reader035.fdocuments.in/reader035/viewer/2022062517/568138d3550346895da08c73/html5/thumbnails/16.jpg)
Remote Entry Systems• With 8 bits for a code you
have a 1/256 chance of a random code working– You don’t want someone
opening your car in a place with lots of cars (like a mall)
• There are also radio scanners that can capture your code– So you want the code to
change each time • Modern remote entry
systems use a 40 bit rolling code