Upload
cordelia-powers
View
215
Download
0
Embed Size (px)
Citation preview
Computer Science I
Storing data. Binary numbers.Classwork/homework: Catch up. Do
analysis of image types.
Overview
• Representation of information. How is everything/anything represented 'in' the computer (in storage)?– ANSWER: everything is represented using 1s and 0s.
What the 1s and 0s mean depends on what the information is, for example, the datatype
• whole number, number with fraction, true/false value, character string, other…
Storage
• Everything (data and programs) is stored in the circuitry of 'the computer'.
• The circuitry includes transistors that are switches: on or off states, 0 or 1. Each switch is called a bit.
• So….numbers are stored using the binary (base 2) system
• Symbols (characters, letters, etc.) are stored using agreed upon systems of encoding– ASCII: 8 bits per character
– UNICODE: 16 bits per character
Why?
• Why not use circuits that can directly represent numbers using the decimal (base 10) system?
• Answer: Easier to make on/off switches than something with 10 states. Easier to build circuitry for calculations for the base 2 addition and base 2 times tables than the ones you remember…
What is stored?
• Numbers: binary number system• Characters: ASCII or UNICODE encoding• Machine instructions• Composite datatypes, for example String
of characters representing text– Will get to arrays
• Images• More…
Recall base 10
• Recall 1s column, 10s column, 100s column
• Recall borrowing (re-grouping) and carrying
• Do problem(s)
Base 2
• Same principle– 1s column, 2s column, 4s column, ????
• Your age? My age?• Addition
– Subtraction? Multiplication?
Joke
Explain joke on shirt
Bits
• A bit is a one or a zero (1 or 0).• 3 bits can hold how many different
patterns? 000, 001, 010, 011, 100, 101, 110, 1114 bits can hold how many different patterns?
• What is the formula?
Byte
• A byte is 8 bits.• See in specs for computers, memory, etc.
KB, Kb, Gb, GB, other.• So, how many patterns, what is the
biggest number, held by a byte?
Another Joke
Base 16• Hexadecimal: used for quick way to
describe bits, mostly commonly for color coding
• Symbols used are 0, 1, 2, …, 9, A, B, C, D, E, F
• You have seen color coding: RGB (red, green blue) in hexadecimal FF0000 is red 00FF00 is green ??
Numbers with fraction partAka numbers with a decimal point• How to represent?• ANSWER: floating point numbers
aka scientific notation– 3.4521 * 102 is the same as 345.21 * 100
– Terminology: 3.4521 (or 345.21) is the mantissa or significand and the 2 (or 0) is the exponent.
• Computer format: use 2 or 16 in place of 10• Example using 32 bits:
– 1 bit for the sign (0 for +, 1 for -)– 8 bits for the exponent – 23 bits for the mantissa (width, i.e., 23, is the precision)
Characters
• ASCII codingThe character A is represented by 01000001
The character a is represented by 01100001
The character 1 is represented by 00110001
The character 2 is represented by 00110010
….
• Unicode is a 16 bit format big enough (hopefully) for all the world's languages
String of characters
…such as a name or a label or a piece of text
• Fixed length: allocate 1 byte (8 bits) for each character– UNICODE 2 bytes
• Variable length: store string in two parts– One part holds length as a number and
pointer (address) of the whole string– String itself
Boolean
• Named after George Boole• True / False• Theoretically: 1 bit, 0 for false, 1 for true
but• The addressability requirement means it
could be 1 byte or even bigger• String of Booleans can be combined.
– A byte can represent the answer to 8 true/false questions.
Images
• There are several different ways to represent images.
• Consider this simple way:– For each pixel, have 3 bytes of information: the
bytes representing the level of red, green and blue.
– So, for an image 400 by 300 pixels, how many bytes required for storage?
Machine instructions: back up
• Processing code is translated, multi-stage process, to basic language of the computer.
• Very, very basic instructions:– LR Load a register (part of the Central Processing
Unit (CPU) with contents at particular address– AR add values in register– JUMP to a new instruction– Etc.
• Contains machine instruction command and other information, such as storage addresses, in binary.
Classwork / Homework
• Catch up. Upload of work past due, but will get some credit.
• Examine images and compare different types in quality and size. Make posting on forum.