Title: Encoding Information as Bit Patterns
1Encoding Information as Bit Patterns
2The Big Picture
- Two Key principles of todays computers
- Instructions are represented as numbers
- Programs can be stored in memory to be read or
written just like numbers - Initially, computers were designed to crunch
numbers, but, as soon as they were commercially
viable, they were designed to process text as
well. - We will try to understand more about representing
numbers
3Objectives
- Look at different techniques of encoding
information - Compare various number systems and positional
notation - Get familiar with base conversion
- Introduce binary encoding of text, numerical
data, images and sound
4What is a Number?
- Number is a theoretical concept in mathematics
- Number System
- A convenient way to represent the number concept
- Well-known system is our Decimal system
5Representing Numbers
- Decimal positional notation uses 10 digits and
few symbols (., /) to represent all of the
values that a number may assume. The digits are
0-9. - Other ways of representing numbers
- Octal, Hexadecimal, Binary
- Roman Numeral system does not use positional
notation
6Base of the number representation
- The number of digits used to represent a number
is called the base of the number (or base of the
number representation). - Decimal notation is base 10
- 0,1,2,3,4,5,6,7,8,9
- Binary notation is base 2
- 0,1
- Octal notation is base 8
- 0,1,2,3,4,5,6,7
- Hexadecimal notation is base 16
- 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F
7Base 60 number representation
- Babylonians had an advanced positional number
system with base 60 - Approximate days for earth to go around sun was
known 365 days 1 year - Babylonians used their base 60 to define number
of degrees in a circle (360o 6 x 60o) - 60 seconds 1 minute
- 60 minutes 1 hour
- 24 hours 1 day
8Why binary for computers?
- Decimals is natural for humans because we have 10
fingers or digits, so, why not use decimal for
computers? - First commercial computer did offer decimal
arithmetic but it was inefficient. - The Problem Computers can only use on, off
signals, so, decimal digit was simply represented
by several binary digits which was more
cumbersome - Less is more.
- - Robert Browning, Andrea del Sarto, 1855
9Positional Notation
- Positional notation represents numbers as a
string of digits, e.g. 123 - Positions in the string are numbered from the
rightmost position, and start with position 0
(zero). - 3 is in position 0
- 2 is in position 1
- 1 is in position 2
10Positional Notation
- Positional notation means that the value of a
digit depends on the position of the digit - The value of the 5 in 50 is different than
the value of the 5 in 2005 - Binary, Octal, Decimal, and Hex are all
positional notation schemes - Roman Numerals are NOT a positional notation
scheme - Value of XIII is determined by adding
11Positional Notation
- The value of the digit n in position p of a
string representing a number in base b is - n x b p
- The value of the number is calculated by adding
the value of each digit in the number - ? (n x b p )
- sum over the terms (n x b p )
12Digits are the same
- What do we mean?
- The value of 0-9 is the same in each base where
those digits appear - Not all bases use all the 10 decimal digits
- Octal (base 8) uses 0-8
- Hex (base 16) uses extra 6 digits with the
following decimal values - A 10
- B 11
- C 12
- D 13
- E 14
- F 15
13Converting TO Decimal
- Use the formula ? (n x b p ) to calculate the
decimal value of the string 123 in - Octal 1238 is
- 1 x 82 2 x 81 3 x 80 8310
- Hex 12316 is
- 1 x 162 2 x 161 3 x 160 29110
14Converting FROM Decimal
- Converting from decimal into a different base
requires long division - Divide the decimal number by the base
- Remainder is 1st digit of the new number
- Divide the quotient by the base
- Remainder is 2nd digit of the new number
- Repeat until quotient is zero and remainder is
less than the base.
15Algorithm for Decimal to Binary Conversion
- Divide the value by the base (2 for binary) and
record the remainder - As long as the quotient obtained is not zero,
continue to divide the newest quotient by 2 and
record the remainder - Now that quotient zero has been obtained, binary
representation is just the string of remainders
listed right to left in the order in which they
were recorded
16Example in text, Page 39
Figure 1.16Applying the algorithm in Figure 1.15
to obtain the binary representation of thirteen
17Lets try it!
- 35 10 converted to binary
- Let R remainder, Q Quotient
- 35/2 gt Q 17, R 1
- 17/2 gt Q 8, R 1
- 8/2 gt Q 4, R 0
- 4/2 gt Q 2, R 0
- 2/2 gt Q 1, R 0
- 1 / 2 gt Q 0, R 1
- Answer 1000112
18Binary to Decimal Conversion
Figure 1.14Decoding the binary representation
100101
19Lets Try it!
- Convert 1000112 to decimal
- 1 x 25 0 x 24 0 x 23 0 x 22 1 x 21 1 x
20 - 32 0 0 0 2 1
- 3510
20Hexadecimal Notation
Figure 1.6The hexadecimal coding system
21Hexadecimal Notation
- Only strings of 0s and 1s could get too long
and hard to process (stream of bits) - Bit patterns in machines tend to have lengths in
multiples of four - Four bits per symbol
- What is 10110010?
- What is 101110101101?
22Decimal to Hex Conversion
- 2310 converted to hexadecimal
- 23 / 16 gives Q 1, R 7
- 1 / 16 gives Q 0, R 1
- So 2310 1716
23Exercise Base Conversions
- Purpose Practice representing numbers in
different bases - Who Groups of 2-3
- Task Perform the conversions shown on the next
slide - Presentation Spokesperson for each group will
report their results when asked, and be able to
explain how the results were derived - Time 10 minutes
24Exercise Working with Bases
- Find the value of ?
- 2510 ?2
- 1101012 ?10
- 1310 ?8
- 4316 ?10
- 9610 ?16
25Answers Working with Bases
- Find the value of ?
- 2510 110012
- 1101012 5310
- 1310 158
- 4316 6710
- 9610 6016
26Conversion Trick
- Binary, Octal, and Hex conversions can be done
very easily by using a binary grouping
technique - Binary numbers use 1 bit groups
- Octal numbers use 3 bit groups
- Hex numbers use 4 bit groups
27Conversion Trick
28Addition
- Remember your addition algorithm?
- Remember sum and carry?
- To add numbers
- Add the digits in a given position
- Divide the result by the base
- The remainder is the new digit for that position
- The quotient is the carry to the next position
29Binary Addition
Figure 1.17The binary addition facts
30Addition
- Binary Addition
- 1 1 10
- 10 10 100
- Octal Addition
- 7 7 16
- 15 5 22
- 12 6 20
- Hex Addition
- A F 19
- 9 B 14
- 18 9 21
- To add numbers
- Add the digits in a given position
- Divide the result by the base
- The remainder is the new digit for that position
- The quotient is the carry to the next position
- A 10
- B 11
- C 12
- D 13
- E 14
- F 15
31Identifying Bases
- Purpose Think about number bases
- Who Groups of 2-3
- Task Identify the base used in each of the
following operations - Presentation Spokespeople will provide answers
when requested - Time 5 minutes
32Archaeological Find!
- You are part of an archaeological team that has
found a valuable stone tablet somewhere on the
islands that were once part of the great
Atlantis. This stone tablet is the first clue in
several thousand years that gives an insight into
the greatness of this ancient culture. Skeletal
remains found years ago shared a common feature
that was classified as an anomaly and never
studied. This tablet contains, to your utter
surprise and dismay, the following calculations.
33Solve the Mystery!
- It was surprising that this civilization,
well-known for its greatness, appeared to not
have mastered simple arithmetic. However, renewed
study of the skeletal remains along with this
tablet, proved the Atlanteans were indeed superb
mathematicians. - Can you guess the common feature about the
skeletons that proved this tablet correct?
34Combinations
- Combinatorics is a branch of mathematics that
studies combinations and complexity - The number of possible combinations resulting
from multiple inputs is the product of the number
of possible input values - How many possible outfits does a wardrobe of 2
suits, 3 ties, and 4 pairs of shoes results in ?
35Result 24 outfits!
4 shoes
3 ties
4 shoes
4 shoes
2 suits
4 shoes
4 shoes
3 ties
4 shoes
36Combinations
- Example
- In arranging your schedule for next term, you
must select one humanities course, one social
science course, and one math course. If there are
10 humanities courses, 7 social science courses,
and 3 math courses, from how many different
possible schedules could you select? - (Assume each course can be taken independently
meaning, no conditional pre-requisites and so on).
37Combinations and Computer Science
- Deals with the number of possible outcomes from a
set of inputs - How many different numbers can be represented by
8 bits? - How many computers can be connected to the
Internet using 32-bit addresses? - How many bits are required to represent true and
false in a computer?
38Exponents
- Remember these rules for working with exponents?
- XN XM XNM
- (XN)M XNM
39Power of 2
- 24 28 212
- 4 22
- 8 4 x 2 22 x 21 23
- 16 4 x 4 22 x 22 24
- 1612 819 (24)12 ((23)19
- 248 257 24857 2105
- How many bits to represent 2n?
- 1 n zeroes n1 bits
40Binary Encoding
- Binary Encoding is the act of converting
non-numeric data into binary numbers so that the
data may be represented by a computer
41Representing Text
- Character codes have been invented to represent
alphanumeric data on a computer - ASCII (American Standard Code for Information
Interchange) uses 8 bits to represent characters - http//www.asciitable.com
- Online reference for ASCII encoding
- EBCDIC (Extended Binary Coded Decimal Interchange
Code) is an alternative 8 bit code - Unicode is a set of 8-,16-,32-bit codes. Unicode
is designed to work in an internationalized
environment. - http//www.unicode.org/
42Images
- Bitmap formats
- Each pixel is encoded
- Bitmap, GIF, JPEG
- Could get large and cumbersome
- Vector formats
- Instructions for drawing the picture are encoded
- Postscript, TrueType fonts
- Makes scaling easier
43Representing Images Bitmap Formats
- Monochrome 1 bit per pixel
- 16 color 4 bits per pixel
- 256 color 8 bits per pixel
- 24-bit color 24 bits per pixel
- JPEG
- Encodes every pixels brightness
- averages color over 4 pixels
- records changes not actual values
- compresses the image
- GIF
- Uses 8 bits per pixel maximum and selective color
palettes to change the appearance of an image.
May reduce the file size by detecting the number
of colors and reducing the number of bits per
pixel. - Compresses the image.
44Bitmap Formats
BMP Format 177Kb
GIF Format 31Kb
JPEG Format 10Kb