EPSII 59:006 Spring 2004.

Slides:



Advertisements
Similar presentations
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Advertisements

Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 2 Number Systems.
Binary Representation Introduction to Computer Science and Programming I Chris Schmidt.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Introduction to Computers and Programming Lecture 7:
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
CS1061 C Programming Lecture 4: Indentifiers and Integers A.O’Riordan, 2004.
Introduction to Computing CPSC 203 January 24, 2006 Heejin Lim Chapter 1 Chapter 2 (part of)
Chapter 2 Data Types, Declarations, and Displays
Hexadecimal and ASCII Lesson Objective: Understand the purpose of ASCII and how to use it. Lesson Outcome: Convert between Hexadecimal and ASCII Convert.
Simple Data Type Representation and conversion of numbers
Cosc175/data1 Data comprised of constants and variables information stored in memory Each memory location has an address Address - number identifying a.
Binary, Decimal and Hexadecimal Numbers Svetlin Nakov Telerik Corporation
C Tokens Identifiers Keywords Constants Operators Special symbols.
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.
Number Systems What is the Standard Base we
Bit Manipulation when every bit counts. Questions on Bit Manipulation l what is the motivation for bit manipulation l what is the binary, hexadecimal,
The Teacher CP4 Binary and all that… CP4 Revision.
The Hexadecimal Number System and Memory Addressing ISAT 121.
CISC105 – General Computer Science Class 9 – 07/03/2006.
The Teacher CP4 Binary and all that… CP4 Revision.
Chapter 19 Number Systems. Irvine, Kip R. Assembly Language for Intel-Based Computers, Translating Languages English: Display the sum of A times.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
These notes were originally developed for CpSc 210 (C version) by Dr. Mike Westall in the Department of Computer Science at Clemson.
EEL 3801C EEL 3801 Part I Computing Basics. EEL 3801C Data Representation Digital computers are binary in nature. They operate only on 0’s and 1’s. Everything.
Data as the computer sees it 1.  Number systems Number systems  Data storage Data storage  Glossary Glossary 2.
Info stored in computer (memory) Numbers All in binaray – can be converted to octal, hex Characters ASCII – 1-byte/char Unicode – 2-byte/char Unicode-table.com/en.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Irvine, Kip R. Assembly Language for Intel-Based Computers 6/e, Signed Integers The highest bit indicates the sign. 1 = negative, 0 = positive.
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Number Representation Lecture Topics How are numeric data items actually stored in computer memory? How much space (memory locations) is.
Data Representation. How is data stored on a computer? Registers, main memory, etc. consists of grids of transistors Transistors are in one of two states,
Binary 101 Gads Hill School. Aim To strengthen understanding of how computers use the binary number system to store information.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
CS 125 Lecture 3 Martin van Bommel. Overflow In 16-bit two’s complement, what happens if we add =
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
 Computers are 2-state devices › Pulse – No pulse › On – Off  Represented by › 1 – 0  BINARY.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Binary numbers. Primary memory Memory = where programs and data are stored – Unit = bit “BIT” is a contraction for what two words? Either a 1 or a 0 (because.
Binary a. express numbers in binary, binary-coded decimal (BCD), octal and hexadecimal;
Lecture 4 Monday Sept 9, Variables and Data Types ►A►A►A►A variable is simply a name given by the programmer that is used to refer to computer storage.
1 Chapter 1: Basic Concepts Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine 9/6/2003.
Objectives Today: P4 Data Types – Floating Points P4 Variable Quiz P3 Iteration and Selection Practical Are you logged on? Then come around the table Unit.
Computer Science 210 Computer Organization
Lecturer: Santokh Singh
How Computers Store Variables
Digital Logic and Computer Organization
Data Representation Binary Numbers Binary Addition
Integer Real Numbers Character Boolean Memory Address CPU Data Types
Chapter 6: Data Types Lectures # 10.
ECE Application Programming
Binary, Decimal and Hexadecimal Numbers
Number System conversions
CS1010 Programming Methodology
Introduction to Abstract Data Types
Computer Science 210 Computer Organization
Number Systems Lecture 2.
Plan Attendance Files Posted on Campus Cruiser Homework Reminder
How Computers Store Data
Computer Organization
Electronic Memory.
Chapter 3 - Binary Numbering System
ECE 120 Midterm 1 HKN Review Session.
Section 6 Primitive Data Types
Presentation transcript:

EPSII 59:006 Spring 2004

Numbers in Computers Why use data types? Number systems - binary, octal, decimal, hexadecimal Data representation - bits, bytes, words (of different sizes) Types Integer Char Float, Double Signed, Unsigned

Data Types Variables are names for places in memory There are different types of variables Different variables require different amounts of information to store them In C the main types are: char, int, float, double

How the Computer Stores Variables Computers must code each variable into series of electronic “on” and “off” switches. Information (both instructions and data) are represented by binary codes (1’s and O’s).

Binary Numbers 1111 == 15 1000 0000 == 128 1111 1111 == 255 0 == 0 10 == 2 11 == 3 100 == 4 101== 5 110 == 6 111 == 7 1000 == 8 1111 == 15 1000 0000 == 128 1111 1111 == 255

Breaking It Down! Binary: a3*23 + a2*22 + a1*21 + a0*20 1001 = 1*23 + 0*22 + 0*21 + 1*20 1001 = 1*8 + 0*4 + 0*2 + 1*1 1001 = 8+1 1001 = 9 Decimal: a3 a2 a1 a0 = a3 * 103 + a2*102 + a1*101 + a0*100

Question What does 0001 1101 Equal in decimal?

Solution 0001 1101 = 16 + 8 + 4 + 1 = 29

Hexadecimal Binary is a pain to work with because the representation is so long There are 16 possible combination of 4 binary digits

Hexadecimal Code 0000 == 0 == 0 0001 == 1 == 1 0010 == 2 == 2 0011 == 3 == 3 0100 == 4 == 4 0101 == 5 == 5 0110 == 6 == 6 0111 == 7 == 7 1000 == 8 == 8 1001 == 9 == 9 1010 == 10 == A 1011 == 11 == B 1100 == 12 == C 1101 == 13 == D 1110 == 14 == E 1111 == 15 == F

Question What is the octal code?

Answer a3a2a1a0 Octal = a3*83 + a2*82 + a1*81 + a0*80

Exercise Convert A9 to binary Convert 1101 1100 to Hex

Solution Convert A9 to binary 1010 1001 Convert 1101 1100 to Hex D C

How Do All These Bits Get Organized? byte n. - A sequence of adjacent bits, usually eight, operated on as a unit by a computer. word n. - Computer Science. A set of bits constituting the primary unit of addressable memory. 4 bits = nibble = 16 states (24) 8 bits = byte = 256 states (28) 16 bits = word = 65536 states (216) => 64K Memory is arranged in bytes – each individual address points to the beginning of a byte.

How are variables stored? Characters are stored as numbers: ASCII : ftp://dkuug.dk/i18n/WG15-collection/charmaps/ANSI_X3.4-1968 Unicode over 65000 characters – every written language. Integers stored as binary Floating point numbers are stored with limited precision according to the IEEE standard. Double precision floats (type double) are preferred for numerical calculations.

Standard Variable Type Storage Used For Storage (bytes) int Integers 4 (usually, but is really implementation-dependent) char Characters 1 float Real numbers 4 double 8

Other Variable Types Type unsigned positive Integers 4 (usually, but is really implementation-dependent) short integers 2 long 4 (usually)

Variable Type Storage Type Storage (bytes) Range of Values int 4 char 1 -128 to 127 float -1.17549435e-38 to 3.40282347e+38 double 8 -2.2250738585072014e-308 to 1.7976931348623157e+308

Finding variable sizes for your computer Use the sizeof() function: printf(“An int is %d bytes ”,sizeof(int)); printf(“and a char is %d bytes\n”,sizeof(char));