bits and bytes and why we have to care in vb!. all computer storage is organized into bytes think of...

34
Bits and Bytes And why we have to care in VB!

Upload: jaquan-glaspell

Post on 29-Mar-2015

218 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Bits and Bytes

And why we have to care in VB!

Page 2: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

All computer storage is organized into bytes

• Think of each byte as a little storage bin• Each byte is made up of 8 bits• Each bit is an electronic circuit that is either on

or off (off = 0, on = 1)• A specific sequence of 0’s and 1’s in a byte is

called a bit pattern

Page 3: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

What kinds of information do you store on your computer?

• numerical values (binary number system)• text/character data (ASCII or Unicode)• program instructions (machine language)• images (jpg, gif, tiff, bmp, wmf, etc.)• video (mp4, mov, avi, wmv, etc.)• music (mp3, wav, wma, au, etc.)

Page 4: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Numerical Values vs Strings (text/characters)

40 Oak St

$40

Page 5: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

“40 Oak St” is a string

001101000011000000100000010011110110000101101011001000000101001101110100

It would be stored like this using ASCII codes

Page 6: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

The 40 in $40 needs to be a numerical value for arithmetic

The numerical value 40 would be stored like this using the binary number system.

00101000

Page 7: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Compare: “40” vs 40

0011010000110000

The text string“40”

The numerical value40

00101000

Page 8: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

How do binary numbers work?Decimal Number System Binary Number System

Base 10 Base 2

10 digits (0,1,2,3,4,5,6,7,8,9) 2 digits (0,1)

Positional values based on powers of 10 Positional values based on powers of 2

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number

8-bit binary number

Page 9: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Binary to Decimal

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 0 1 1 0 1 0 1 0

What is the decimal value of the bit pattern 01101010 ?

Simple! Just add up the positional values where the 1’s appear: 64 + 32 + 8 + 2 = 106

So, we say that 011010102 = 106 decimal

Page 10: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number

How can we represent the decimal value 151 in binary?

Simple! Just think about money and consider positional values as coins and 151 “cents” as the change we must make.

Then “count change” from largest “denomination” to smallest until total value of change is accumulated.

Page 11: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1

How can we represent the decimal value 151 in binary?

Running Total: 128

Page 12: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1 0

How can we represent the decimal value 151 in binary?

Running Total: 128

Page 13: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1 0 0

How can we represent the decimal value 151 in binary?

Running Total: 128

Page 14: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1 0 0 1

How can we represent the decimal value 151 in binary?

Running Total: 128 + 16 = 144

Page 15: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1 0 0 1 0

How can we represent the decimal value 151 in binary?

Running Total: 128 + 16 = 144

Page 16: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1 0 0 1 0 1

How can we represent the decimal value 151 in binary?

Running Total: 128 + 16 + 4 = 148

Page 17: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1 0 0 1 0 1 1

How can we represent the decimal value 151 in binary?

Running Total: 128 + 16 + 4 + 2 = 150

Page 18: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Converting from Decimal to Binary

Positional Values

128 64 32 16 8 4 2 1

27 26 25 24 23 22 21 20

Binary Number 1 0 0 1 0 1 1 1

How can we represent the decimal value 151 in binary?

Running Total: 128 + 16 + 4 + 2 + 1 = 151

So, 151 decimal = 100101112

Page 19: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Compare: “40” vs 40

0011010000110000

The text string“40”

The numerical value40

00101000

Page 20: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Consider GPA Program

Input?

Output?

Page 21: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Consider GPA Program

Input

Output

Page 22: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Bottom Line

All input values provided via text boxes on VB forms are stored as text

All output values provided placed in labels on VB forms are stored as text

To use values in computations for processing in VB, the values must be numeric

HOWEVER

Page 23: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Beginning of GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Note: credithrs, qualpts, and gpaare called variables

Page 24: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Input Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 25: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Input Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 26: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Input Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

00101000

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 27: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Input Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

00101000

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 28: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Input Phase GPA ProgramOn Screen Behind the Scenes

In memory (RAM)

0010100010100000

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 29: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Processing Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

0010100010100000

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 30: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Processing Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

001010001010000000000100

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 31: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Output Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

001010001010000000000100

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 32: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Output Phase GPA ProgramOn Screen Behind the Scenes

in Memory (RAM)

001010001010000000000100

credithrsTxt

qualptsTxt

gpaLbl

credithrs

qualpts

gpa

Page 33: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Good News is …

• We don’t have to directly handle the nitty-gritty details of converting text to binary for input

• We don’t have to directly handle the nitty-gritty details details of converting binary to text for output

• Phew!

Page 34: Bits and Bytes And why we have to care in VB!. All computer storage is organized into bytes Think of each byte as a little storage bin Each byte is made

Not So Good News is …

• We do have to explicitly ask VB to do the conversions when necessary