lec03a-data_types

lec03a-data_types - CSC 1111 Introduction to Computing...

Info iconThis preview shows pages 1–12. Sign up to view the full content.

View Full Document Right Arrow Icon
1 CSC 1111 Introduction to Computing using C++ Data Representations and Advanced Data Types
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
2 Questions to be answered … How large/small can integers and floating point numbers be? How do computers represent integers, floating point numbers, and characters? Why 2.1 – 2.0 – 0.1 != 0.0 ? Can you assign a floating point number to a variable of type int ? How can you represent ♠, , ♣, in a program that implements a card game? How can you represent date in a program?
Background image of page 2
3 Outlines Data Range and Representation Integers (int) Floating Point Numbers (double) Implicit Type Conversion Explicit Type Conversion (Casting) Other Built-in C++ Types Representing Other Types of Data Simple use of class
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4 int Each value of type int is represented using 4 bytes or 32 bits How many different values can be represented using 32 bits? Half for negative integers, and half for non- negative integers -(2 31 ), -(2 31 - 1), … , -2, -1, 0, 1, 2, …, 2 31 - 1 or 2147483648, …, -2, -1, 0, 1, 2, …, 2147483647
Background image of page 4
5 2-byte integers On some systems, int is represented using only 2 bytes. What are the largest and the smallest possible values of an int -type variable on these systems?
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
6 Representing Integers Computers use binary numbering system to represent integers. Decimal digits: 0, 1, 2, …, 9 Binary digits: 0, 1               =  1 x 8  +   0 x 4  +  1 x 2  +  1 x 1
Background image of page 6
7 Decimal to Binary Number Conversion How to convert 18 10  to the equivalent binary  number? 2 |18 ---- 0 2 | 9 ---- 1 2 | 4 ---- 0 2 | 2 ---- 0 2 | 1 ---- 1 0 Remainders from dividing the number by 2 Keep dividing the number until it becomes zero Read the remainders bottom up to get the binary representation of 18, which is 10010 2
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
8 Representing Positive and Negative Integers Two's Complement – a binary numbering system that can represents both negative and positive integers. e.g. (assume 8-bit integers) 00010010 (=18 10 ) -------- BitwiseNegation 11101101 + 1 --------- 11101110 (=-18 10 ) 11101110 (=-18 10 ) -------- 00010001 + 1 --------- 00010010 (=18 10 )
Background image of page 8
9 Representing Positive and Negative Integers In a 2's complement binary number system, all negative numbers have 1 as the most significant (left-most) digit. 0 0000000 (zero) 1 1111111 (negative) 1 0000000 (negative) 0 1111111 (positive) Note: In these examples, 8-bit integers are assumed. What decimal values do the last three binary numbers represent?
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
10 Representing Floating Point Numbers A floating point number can be expressed as 0.d 1 d 2 d 3 …d m x 10 n Mantissa Exponent According to IEEE 754 standard, a single precision floating point number is represented in the form: Note: You don't have to know the exact representation.
Background image of page 10
11 Limitation of floating point numbers Limited number of bits to represent mantissa and exponents.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 12
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 35

lec03a-data_types - CSC 1111 Introduction to Computing...

This preview shows document pages 1 - 12. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online