+ All Categories
Home > Documents > SIMS-201 Representing Information in Binary. 2 Overview Chapter 3: The search for an appropriate...

SIMS-201 Representing Information in Binary. 2 Overview Chapter 3: The search for an appropriate...

Date post: 23-Dec-2015
Category:
Upload: owen-bridges
View: 213 times
Download: 0 times
Share this document with a friend
23
SIMS-201 Representing Information in Binary
Transcript
Page 1: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

SIMS-201

Representing Information in Binary

Page 2: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

2

Overview

Chapter 3: The search for an appropriate code Bits as building blocks of information Binary to decimal conversion Decimal to binary conversion

Page 3: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

3

Representing information in binary form In order to efficiently store, transmit, process and retrieve

information, we need a process for encoding the information The encoding process is a method of representing information

using a finite number of basic elements, called an alphabet Examples of written alphabets are:

The English alphabet: 26 lower case, 26 upper case, 10 numbers and 32 special characters=94 characters

The Chinese alphabet (Mandarin): 40, 000 characters A comparison between these alphabets shows us that the

Chinese alphabet is a more powerful code as it can convey more information with a single complex character (symbol). Fewer characters are required to communicate an idea

However, this code is very complex and the task of distinguishing one character from the other at the receiving end is highly challenging

Page 4: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

4

We therefore would require a more robust scheme since reliable manipulation of information depends upon resistance to errors

The fewer symbols the code has, the easier it is to distinguish the symbols from each other

The code with the minimum number of symbols (2) is called the binary code

It consists of two distinct symbols: 0 and 1

Any information can be coded using only these two symbols called bits: Binary digits

Page 5: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

5

Why Use a Code with Only Two Values? A binary system is more resistant to errors The two symbols are highly distinguishable from one another. Consider a compact laser disc for music or computer storage:

A CD is comprised of an enormous number of domains, each of which stores one bit.

Each domain either has a smooth surface that reflects the laser or a “pit” which doesn’t reflect the laser. It’s very clear which of the two values is held by each domain.

If, instead of 2 values, each domain held 3 values (domains of zero, partial, and high reflectivity) a simple fingerprint might create errors.

The 2 clear values make the system simple and reliable. Two values correspond well to the “on” and “off” states of

electronic switches that comprise digital computers.

Page 6: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

6

Bits in the physical world

Generation Varying the voltage in a circuit Varying the light intensity (ex: switch light on or off)

Storage Magnetic disk: Magnetized in one of two directions:

“up” or “down” Compact disc: Constructed to reflect or not reflect light

using a reflective surface or pit Transmission media

Electrical cables (wires) Optical fibers Air

Page 7: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

7

Representing Information in Binary Form

BInary digiTal symbols (BITs) form a universal language for any:

Numbers Text Sound Images Video Anything else you can imagine…

How is this possible????How can numbers and text be How can numbers and text be represented in binary code????represented in binary code????

Page 8: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

8

How Do We Normally Represent Numbers?

We normally don’t use Binary Digits (Bits) (in which a single placeholder can hold only 0 or 1) in everyday life.

We use Decimal Digits - a single placeholder can hold one of ten numerical values between 0 and 9.

Digits are combined together into larger numbers. For example: 8,234 is made up of 4 digits. The 4 holds the

“1s place,” the 3 holds the “10s place,” the 2 holds the “100s place” and the 8 holds the “1000s place.”

Before we discuss binary code, let’s think Before we discuss binary code, let’s think about the number system we use every about the number system we use every day.day.

Page 9: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

9

The Decimal System

Decimal digits are combined to create larger numbers4,567 => (4 x 103) + (5 x 102) + (6 x 101) + (7 x 100)

10 raised to the power of … 100 =1 101 =10 102 =10x10=100 103 =10x10x10=1,000 104 =10x10x10x10=10,000 and so on

Also called Base-10 system

There are other ways of representing numbers other than using the digits 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9.

We have ten We have ten fingers and use ten fingers and use ten

digits! digits! Coincidence?Coincidence?

Page 10: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

10

Comparing the Decimal Number System to the Binary Number System

While people routinely use decimal digits, computers use binary digits.

The decimal system uses ten numbers (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) to represent all values. The binary system uses two numbers (0 and 1) to represent all values.

In other words, computers use the “base-2” system rather than the “base-10” system.

Counting in binary is simple (different, but simple) because you use powers of two instead of ten. Example follows.

Page 11: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

11

Binary to Decimal ConversionThe same as calculating the value of a decimal system The same as calculating the value of a decimal system number except use powers of two instead of powers of number except use powers of two instead of powers of ten.ten.

• The binary number The binary number 11011101 can be converted to decimal as can be converted to decimal as follows:follows:

((11x2x233) + () + (11x2x222) + () + (00x2x211) + () + (11x2x200) = 8 + 4 + 0 ) = 8 + 4 + 0 + 1 = + 1 = 1313

• For understanding binary, it’s helpful to have a good For understanding binary, it’s helpful to have a good command of powers of 2:command of powers of 2:

20 = 121 = 222 = 2x2 = 423 = 2x2x2 = 824 = 2x2x2x2 = 1625 = 2x2x2x2x2 = 32

26 = 2x2x2x2x2x2 = 6427 = 2x2x2x2x2x2x2 = 12828 = 2x2x2x2x2x2x2x2 = 25629 = 2x2x2x2x2x2x2x2x2 = 512210 = 2x2x2x2x2x2x2x2x2x2 = 1024and so on...

Page 12: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

12

Binary versus Decimal Numbers

2s p

lace

1s p

lace

4s p

lace

8s p

lace

Another Way to Think About It.

1 0 1 0 11 0 1 0 1

16s

plac

e

10s

plac

e1s

pla

ce

100s

pla

ce

1,00

0s p

lace

9 5, 1 0 79 5, 1 0 7

10,0

00s

plac

e

9 x 10,000 = 90,000+ 5 x 1,000 = 5,000

+ 1 x 100 = 100+ 0 x 10 = 0

+ 7 x 1 = 7_______________

= 95,107 (10)

1 x 16 = 16+ 0 x 8 = 0+ 1 x 4 = 4+ 0 x 2 = 0+ 1 x 1 = 1

_______________= 21 (10)

Decimal NumberDecimal Number Binary NumberBinary Number

Page 13: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

13

Another Example: Converting Binary to Decimal

A computer generates the following sequence of bits: 110101(2)

How do we convert 110101(2) into decimal?

(1x2(1x255) + (1x2) + (1x244) + (0x2) + (0x233) + (1x2) + (1x222) + (0x2) + (0x211) + (1x2) + (1x200) ) = 32 + 16 + 0 + 4 + 0 + 1 = = 32 + 16 + 0 + 4 + 0 + 1 = 5353(10)(10)

110101110101(2)(2) = = 5353(10)(10)

Page 14: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

14

Real World Example: The Internet Address

An Internet address, known as an IP address for “Internet Protocol” is comprised of four binary octets, making it a 32-bit address.

IP addresses, difficult for humans to read in binary format, are often converted to “dotted decimal format.”

To convert the 32-bit binary address to dotted decimal format, divide the address into four 8-bit octets and then convert each octet to a decimal number.

Each octet will have one of 256 values (0 through 255)

Converting a 32-bit Internet address into dotted decimal formatConverting a 32-bit Internet address into dotted decimal format

192.48.29.253192.48.29.253(IP address in dotted decimal form)(IP address in dotted decimal form)

Page 15: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

15

Real World Example: The Internet Address

Convert the following 32-bit Internet address into dotted decimal format:Convert the following 32-bit Internet address into dotted decimal format:

0101111000010100110000111101110001011110000101001100001111011100

1) Divide the IP address into four octets01011110 01011110 00010100 00010100 11000011 11000011 1101110011011100

2) Convert each binary octet into a decimal number2) Convert each binary octet into a decimal number01011110 = 64+16+8+4+2 = 9401011110 = 64+16+8+4+2 = 9400010100 = 16+4 = 2000010100 = 16+4 = 2011000011 = 128+64+2+1 = 19511000011 = 128+64+2+1 = 19511011100 = 128+64+16+8+4 = 220 11011100 = 128+64+16+8+4 = 220

3) Write out the decimal values separated by periods3) Write out the decimal values separated by periods94.20.195.22094.20.195.220

Page 16: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

16

Decimal to Binary Conversion Sometimes it can be done intuitively. For example:

The decimal number 1 represented in 8-bit binary is: 00000001.

The decimal number 128 represented in 8-bit binary is: 10000000.

The decimal number 129 represented in 8-bit binary is: 10000001.

The decimal number 2 represented in 8-bit binary is: 00000010.

The decimal number 4 represented in 8-bit binary is: 00000100.

The decimal number 6 represented in 8-bit binary is: 00000110.

But what are we really doing mathematically?

Page 17: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

17

____ ____ ____ ____ ____ ____ ____ ____

Convert the Decimal Number 174 to a binary octet

____ ____ ____ ____ ____ ____ ____ ____

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

Step 1: Compare 174 to 128. 174>128 so place a 1 in the 128s place and subtract 174-128 = 46

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

11

Step 2: Compare 46 to 64. 46<64 so place a 0 in the 64s place and continue with 46.

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

11 00

____ ____ ____ ____ ____ ____ ____ ____

Page 18: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

18

Reversing the Process: Converting a Decimal Number to Binary

____ ____ ____ ____ ____ ____ ____ ____

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

Step 3: Compare 46 to 32. 46>32 so place a 1 in the 32s place and subtract 46-32 = 14

____ ____ ____ ____ ____ ____ ____ ____

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

11

Step 4: Compare 14 to 16. 14<16 so place a 0 in the 16s place and continue with 14.

____ ____ ____ ____ ____ ____ ____ ____

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

11 00

00 11

00

Step 5: Compare 14 to 8. 14>8 so place a 1 in the 8s place and subtract 14-8=6.

11 00 11

Page 19: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

19

____ ____ ____ ____ ____ ____ ____ ____

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

00

Step 6: Compare 6 to 4. 6>4 so place a 1 in the 4s place and subtract 6-4=2.

11 00 11 11

____ ____ ____ ____ ____ ____ ____ ____

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

00

Step 7: Compare 2 to 2. 2=2 so place a 1 in the 2s place and subtract 2-2=0.There is no remainder left to convert, so also place a 0 in the 1s place.

11 00 11 11 11

____ ____ ____ ____ ____ ____ ____ ____

1s place

2s place

4s place

8s place

16s place

32s place

64s place

128s place

0011 00 11 11 11 0011

The decimal number 174 has been converted to the binary number 10101110

Page 20: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

20

Binary Conventions Most Significant Bit (MSB) and Least Significant Bit (LSB)

Decimal Example: 64 6 is the Most Significant Digit 4 is the Least Significant Digit

Binary: 1000000 1 is the MSB 0 on the right is the LSB

Subscripts: Note that the subscript “2” makes it clear a number is in binary format and the subscript “10” makes it clear a number is in decimal format.

This avoids confusion between a number like 110101 which can either be binary, written as 110101(2) or decimal, written as 110,101(10)

Page 21: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

21

If there is a “1” in the LSB of a binary number, then its decimal equivalent is an odd number

If there is a “0” in the LSB of a binary number, then its decimal equivalent is an even number

Page 22: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

22

In-Class Examples

Convert 12(10) to binary representation

Convert 1010101(2) to decimal

Convert 256(10) to binary representation

Convert 10001110(2) to decimal

Page 23: SIMS-201 Representing Information in Binary. 2  Overview Chapter 3: The search for an appropriate code Bits as building blocks of information Binary.

23

Exercises

Convert the following to binary form: 810

4010

10110

Convert the following to decimal form: 11002

001100102

011112


Recommended