How Computers Store Variables

Slides:



Advertisements
Similar presentations
Computer Basics Binary Bits & Bytes
Advertisements

Data Representation. Units & Prefixes Review kilo, mega, and giga are different in binary! bit (b) – binary digit Byte (B) – 8 binary digits KiloByte.
Digital Data Representation
Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
Processing Data.
Representation and Conversion of Numeric Types 4 We have seen multiple data types that C provides for numbers: int and double 4 What differences are there.
Lecture 2: Topics Bits and Bytes Primitive Types Casting Strings Boolean expressions.
Introduction to Information Technology
Number Systems & Logic Gates Day 1
Codes and number systems Introduction to Computer Yung-Yu Chuang with slides by Nisan & Schocken ( ) and Harris & Harris (DDCA)
CREATED BY, MS. JENNIFER DUKE BITS, BYTES, AND UNITS OF MEASUREMENT.
Bits, Bytes, KiloBytes, MegaBytes, GigaBytes & TeraBytes.
Computer Storage & Representing Numbers CE 311 K - Introduction to Computer Methods Daene C. McKinney.
Memory Terminology & Data Representation CSCI 1060 Fall 2006.
Data and Program Representation
Data Representation S2. This unit covers how the computer represents- Numbers Text Graphics Control.
Data Representation Int 2 Computing Unit 1 – Computer Systems St Kentigern’s Academy.
Data Representation A series of eight bits is called a byte. A byte can be used to represent a number or a character. As you’ll see in the following table,
Fill in the blanks: (1) _________ has only two possible values 0 and 1. (2) There are __________bits in a byte. (3) 1 kilobyte of memory space can store.
Why does it matter how data is stored on a computer? Example: Perform each of the following calculations in your head. a = 4/3 b = a – 1 c = 3*b e = 1.
First Program.  The type of all data used in a C program must be specified  A data type is a description of the data being represented ▪ That is, a.
Representing numbers and Basic MATLAB 1. Representing numbers  numbers used by computers do not behave the same as numbers used in mathematics  e.g.,
Primitive Variables.
Numerical Representation Intro to Computer Science CS1510, Section 2 Dr. Sarah Diesburg 1.
Bits and Bytes IGCSE. A binary number is either a 0 or a 1 and is known as a 'bit' or b inary dig it. However, the CPU cannot deal with just one bit at.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Marr CollegeHigher ComputingSlide 1 Higher Computing: COMPUTER SYSTEMS Part 1: Data Representation – 6 hours.
Computer Science Binary. Binary Code Remember the power supply that is inside your computer and how it sends electricity to all of the components? That.
Data Representation (in computer system). Data Representation How do computers represent data? b The computers are digital Recognize.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Matlab Data types, input and output. Data types Char: >> a = ‘ Jim ’ Char: >> a = ‘ Jim ’ Numeric: uint8, uint16, uint32, uint64 int8, int16, int32, int64.
Computer Math CPS120: Binary Representations. Binary computers have storage units called binary digits or bits: Low Voltage = 0 High Voltage = 1 all bits.
Data Representation.
ASCII AND EBCDIC CODES By : madam aisha.
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
Understanding Computers
Binary a. express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal;
Binary Numbers. Base 10 and Base 2  We normally work with numbers in base 10.  In base 10 we use the digits 0, 1, 2, 3, 4, 5, 6, 7, 8 and 9.  Everything.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
CC111 Lec#2 The System Unit The System Unit: Processing and Memory Lecture 2 Binary System.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Understanding Binary Understanding Computers. Understanding Computers L3 – Understanding Binary Learning Objectives All will Understand why all data is.
Numerical Representation Intro to Computer Science CS1510 Dr. Sarah Diesburg 1.
Nat 4/5 Computing Science Data Representation Lesson 3: Storing Text
Computer Science 210 Computer Organization
Understanding binary Understanding Computers.
MATLAB® An Introduction.
Data Representation N4/N5.
3.1 Denary, Binary and Hexadecimal Number Systems
Data Representation Binary Numbers Binary Addition
Chapter 6: Data Types Lectures # 10.
ECE Application Programming
Numerical Representation
Memory Parts of a computer
Information Support and Services
What is Binary? Binary is a two-digit (Base-2) numerical system, which computers use to process and store data. The reason computers use the binary system.
EPSII 59:006 Spring 2004.
Unit 2.6 Data Representation Lesson 1 ‒ Numbers
Other Kinds of Arrays Chapter 11
Other Kinds of Arrays Chapter 11
Numerical Representation
Fundamentals of Programming I Number Systems
Computer Science 210 Computer Organization
Binary Data representation
Numerical Representation
LO1 – Understand Computer Hardware
Technology 3 Bits & Bytes.
Variables and Constants
Numerical Representation
Presentation transcript:

How Computers Store Variables

How Computers Store Variables Suppose we type the following commands in MATLAB: EDU>> y = 42; EDU>> FavoriteDay = ‘Friday’ We know MATLAB stores the values associated with the variables, y and FavoriteDay, in memory. How are these values stored?

How Computers Store Variables Computers store all data (numbers, letters, instructions, …) as strings of 1s and 0s (bits). A bit is short for binary digit. It has only two possible values: On (1) or Off (0).

Terminology A bit is short for binary digit. It has only two possible values: On (1) or Off (0). A byte is simply a string of 8 bits. A kilobyte (kB) is 1000 bytes A megabyte (MB) is 1,000,000 bytes A gigabyte (GB) is 1,000,000,000 bytes For a sense of size, click on link below: http://highscalability.com/blog/2012/9/11/how-big-is-a-petabyte-exabyte-zettabyte-or-a-yottabyte.html

Numeric Data Types MATLAB has several different options for storing numbers as bits. Unless you specify otherwise, all numbers in MATLAB are stored as doubles. Name Description Range double 64 bit floating point -1.79769313486232E308 to -4.94065645841247E-324 4.94065645841247E-324 to 1.79769313486232E308 single 32 bit floating point -3.402823E38 to -1.401298E-45 1.401298E-45 to 3.402823E38 uint8 8 bit unsigned integer Integers from 0 to 255 int8 8 bit signed integer Integers from -128 to 127 uint16 16 bit unsigned integer Integers from 0 to 65535 int16 16 bit signed integer Integers from -32768 to 32767 uint32 32 bit unsigned integer Integers from 0 to 4294967295 int32 32 bit signed integer Integers from -2147483648 to 2147483647

Data Types: int8, uint8, int16, uint16, int32, uint32 These data types work for integers as long as the integers don’t exceed the range for the data type chosen. They take up less memory space than doubles. They don’t work for non-integers. If you create a variable that is an int8 and try to assign it a value of 14.8, that variable will be assigned a value of 15 instead (closest integer within the range). One common application for integer data types is image data (jpeg, png, …)

Data Types: double and single A double uses 64 bits to store a number. A single uses 32 bits to store a number. Doubles and singles can be used to represent both integers and non-integers.

Why should I care how data is stored in a computer? Example: Perform each of the following calculations in your head. a = 4/3 b = a – 1 c = 3*b e = 1 – c What does MATLAB get?

Why should I care how data is stored in a computer? What does MATLAB get? a = 4/3 = 1.3333 b = a – 1 = 0.3333 c = 3*b = 1.0000 e = 1 – c = 2.2204e-016 It is not possible to perfectly represent all real numbers using a finite string of 1s and 0s.

Comments Not all numbers can be represented exactly even using 64 bit doubles. If we do many, many calculations with numbers which are just a tiny bit off, that error can grow very, very large depending on the type of computations being performed. 64 bit doubles have a huge, but still limited range. What happens if we exceed it? Try the following: EDU>> a = 373^1500 EDU>> b = factorial(172)

ASCII Code When you press a key on your computer keyboard, the key that you press is translated to a binary code. A = 1000001 (Decimal = 65) a = 1100001 (Decimal = 97) 0 = 0110000 (Decimal = 48)

ASCII Code

Strings in MATLAB MATLAB stores strings as an array of characters using the ASCII code. Each letter in a string takes up two bytes (16 bits) and the two bytes are the binary representation of the decimal number listed in the ASCII table. Try the following in MATLAB: EDU>> month = ‘August’ EDU>> double(month)