48
Binary CSCE 101 Slides Courtesy of: Prof. Portia Plante

Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

  • Upload
    others

  • View
    6

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

BinaryCSCE 101

Slides Courtesy of: Prof. Portia Plante

Page 2: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

How is Information Stored

• Information is stored in the computer as binary numbers (0’s and 1’s). Even images are stored in this way, where a combination of 0’s and 1’s represent each color in the picture

• Each binary number is a switch where 0 is off and 1 is on

• How to read/write binary:

– http://www.youtube.com/watch?v=0qjEkh3P9RE

Slides Courtesy of: Prof. Portia Plante

Page 3: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

This is how computer should look like?

Page 4: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Base 10

• The system we generally talk about numbers is in a 10 based system, also called decimal

• In 10 based system we talk about how many 1’s we have, how many 10’s, how many 100’s etc

• For example the following number 4567 is

– 7 ones

– 6 tens

– 5 hundreds

– 4 thousands

Slides Courtesy of: Prof. Portia Plante

Page 5: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Base 10

Each of the categories, ones, tens, hundreds, thousands, … are different powers of 10

103 = 1000 102 = 100 101 = 10 100 = 1

4 5 6 7

Slides Courtesy of: Prof. Portia Plante

Page 6: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Binary (Base 2)

Now the categories we use to represent a number are powers of 2

26 = 64 25 = 32 24 = 16 23 = 8 22 = 4 21 = 2 20 = 1

Slides Courtesy of: Prof. Portia Plante

Page 7: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Binary (Base 2)

What is the number 1101 in the two based system?

First we put the number in the chart, aligning it to the right

26

6425

3224

1623

822

421

220

1

Then we add up the numbers 1 (8), 1 (4) and 1 (1)

which means the number is 8+4+1 = 13

1 1 0 1

Slides Courtesy of: Prof. Portia Plante

Page 8: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

PracticeConvert the binary number to decimal110110

Answer110110 = 32 + 16 + 4 + 2 = 54

26

6425

3224

1623

822

421

220

1

1 1 0 1 1 0

Slides Courtesy of: Prof. Portia Plante

Page 9: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

PracticeConvert the binary number to decimal000111

Answer000111 = 4 + 2 + 1 = 7

26

6425

3224

1623

822

421

220

1

0 0 0 0 1 1 1

Slides Courtesy of: Prof. Portia Plante

Page 10: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

PracticeConvert the binary number to decimal0100011

Answer0100011 = 32 + 2 + 1= 35

26

6425

3224

1623

822

421

220

1

0 1 0 0 0 1 1

Slides Courtesy of: Prof. Portia Plante

Page 11: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 12: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 13: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 14: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 15: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Practice

Convert 3567 to binary?

Page 16: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Practice

Convert 3567 to binary?

Ans : 110111101111

Page 17: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Practice

What is the binary equivalent of 2?

Page 18: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Ans: 10

Page 19: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

ADDITION

Page 20: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Addition (decimal)

Page 21: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Addition (binary)

Page 22: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 23: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Addition (binary)

Page 24: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Addition (binary)

So can we count in binary?

Page 25: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Counting in binary (4 bits)

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

0000

0001

Page 26: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Practice

101110

+ 11011

Page 27: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Practice

1 1 1 1 1

101110

+ 11011

1001001

Page 28: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 29: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 30: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Hexadecimal (Base 16)

• Now the categories we use to represent a number are powers of 16

• Since, our numbers go higher then 10 we need more characters. Our numbers are now…

0 1 2 3 4 5 6 7 8 9 A B C D E F

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Slides Courtesy of: Prof. Portia Plante

Page 31: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Hexadecimal (Base 16)

Now the categories we use to represent a number are powers of 16

165 = 321048576

164 = 65536

163 = 4096

162 = 256

161 = 16 160 = 1

Slides Courtesy of: Prof. Portia Plante

Page 32: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Hexadecimal (Base 16)

What is the number 123 in the 16 based system?

First we put the number in the chart, aligning it to the right

Then we add up the numbers 1 (256), 2 (16) and 3 (1)

which means the number is 256+32+3 = 291

165 = 321048576

164 = 65536

163 = 4096

162 = 256

161 = 16 160 = 1

1 2 3

Slides Courtesy of: Prof. Portia Plante

Page 33: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Hexadecimal (Base 16)

Let’s try ABC in the 16 based system?

First we put the number in the chart, aligning it to the right

Then we add up the numbers 10 (256), 11 (16) and 12 (1)

which means the number is 2560+176+12 = 2748

165 = 321048576

164 = 65536

163 = 4096

162 = 256

161 = 16 160 = 1

A B C

Slides Courtesy of: Prof. Portia Plante

Page 34: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Hexadecimal (Base 16)

Let’s try taking a decimal number and converting it to Hexadecimal. Let’s convert the number 3000. We do this by repeatedly dividing by 16, the remainder goes on the farthest right column.3000/16 = 187 R 8 (Put 8 in farthest right)187/16 =11 R 11 (But B in next right)11/16 = 0 R 11 (Put B in next right)

165 = 321048576

164 = 65536

163 = 4096

162 = 256

161 = 16 160 = 1

0 0 0 B B 8

Slides Courtesy of: Prof. Portia Plante

Page 35: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 36: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 37: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 38: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 39: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 40: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning
Page 41: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

ASCII

• Stands for American Standard Code for Information Interchange

• The way we represent English characters as numbers (binary)

• Each letter is assigned a number form 0 to 1

A = 01000001

B = 01000010

C = 01000011

Slides Courtesy of: Prof. Portia Plante

Page 42: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Text Compression

• Can take body of text and make it smaller

• Makes it more feasible for you to send these files

• Will find simplify repeated patterns so they take up less space.

the rain in Spain falls mainly on the plain.

becomes

? r! in Sp! falls m!ly on ? pl!. ! = ain? = the

Slides Courtesy of: Prof. Portia Plante

Page 43: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Color

• Colors are made up of a certain percent of: Red, Green, and Blue. e.g.

• We use binary numbers to represent different colors

Red Green Blue Color

0 0 0 Black

255 255 255 White

255 255 0 Yellow

255 130 255 Pink

Slides Courtesy of: Prof. Portia Plante

Page 44: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Images

• Each pixel of color in an image is represented by a binary number

• The more pixels in an image the less pixelated the image looks, the higher the resolution, and the more space it takes up (The extra pixel data needs to be stored)

Slides Courtesy of: Prof. Portia Plante

Page 45: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

Image Compression

• In a vector image there is a lot of repeated color.

• Hence the compression can be very effective, and you can use lossless compression.

Slides Courtesy of: Prof. Portia Plante

Page 46: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

JPG

• JPG Images is a compressed file format , making it take up less space on your website and become faster to load

• The compression is lossy. This means that some of the image data is actually lost; however, the change in quality is said to be invisible to the human eye.

• JPG compression works well for pictures

• JPG does not work well for lettering or simple images of few colors.

Slides Courtesy of: Prof. Portia Plante

Page 47: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

GIF

• GIF uses a losless compression.

• Only supports 256 colors

• GIF is better than JPG for images that have few colors. Simple images.

• Images like sunsets have tons of colors, even though they are close in shade and should use JPG rather than GIF.

Slides Courtesy of: Prof. Portia Plante

Page 48: Binary - Computer Science & Ebjoshi/csce101/attachments/02-binary.pdf · Binary (Base 2) What is the number 1101 in the two based system? First we put the number in the chart, aligning

PNG

• An improvement on GIF

• Can be compressed slightly more, and supports more transparency.

Slides Courtesy of: Prof. Portia Plante