19
Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types.

Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

Embed Size (px)

Citation preview

Page 1: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

Computer Science I

Storing data. Binary numbers.Classwork/homework: Catch up. Do

analysis of image types.

Page 2: 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…

Page 3: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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

Page 4: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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…

Page 5: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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…

Page 6: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

Recall base 10

• Recall 1s column, 10s column, 100s column

• Recall borrowing (re-grouping) and carrying

• Do problem(s)

Page 7: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

Base 2

• Same principle– 1s column, 2s column, 4s column, ????

• Your age? My age?• Addition

– Subtraction? Multiplication?

Page 8: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

Joke

Explain joke on shirt

Page 9: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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?

Page 10: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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?

Page 11: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

Another Joke

Page 12: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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 ??

Page 13: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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)

Page 14: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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

Page 15: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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

Page 16: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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.

Page 17: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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?

Page 18: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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.

Page 19: Computer Science I Storing data. Binary numbers. Classwork/homework: Catch up. Do analysis of image types

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.