350 likes | 462 Views
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 up of 8 bits Each bit is an electronic circuit that is either on or off (off = 0, on = 1)
E N D
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 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
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.)
Numerical Values vsStrings (text/characters) 40 Oak St $40
“40 Oak St” is a string It would be stored like this using ASCII codes
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.
Compare: “40” vs 40 The text string “40” The numerical value 40
How do binary numbers work? 8-bit binary number
Converting from Binary to Decimal 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
Converting from Decimal to Binary 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.
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128 + 16 = 144
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128 + 16 = 144
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128 + 16 + 4 = 148
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128 + 16 + 4 + 2 = 150
Converting from Decimal to Binary How can we represent the decimal value 151 in binary? Running Total: 128 + 16 + 4 + 2 + 1 = 151 So, 151 decimal = 100101112
Compare: “40” vs 40 The text string “40” The numerical value 40
Consider GPA Program Input? Output?
Consider GPA Program Input Output
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 HOWEVER To use values in computations for processing in VB, the values must be numeric
Beginning of GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa Note: credithrs, qualpts, and gpa are called variables gpaLbl
Input Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Input Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Input Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Input Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Input Phase GPA Program On Screen Behind the Scenes In memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Processing Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Processing Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Output Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
Output Phase GPA Program On Screen Behind the Scenes in Memory (RAM) credithrsTxt credithrs qualptsTxt qualpts gpa gpaLbl
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!
Not So Good News is … • We do have to explicitly ask VB to do the conversions when necessary