lec03a-data_types

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

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

1 CSC 1111 Introduction to Computing using C++ Data Representations and Advanced Data Types

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

View Full Document
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?
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

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

View Full Document
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
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?

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

View Full Document
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
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

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

View Full Document
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 )
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?

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

View Full Document
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.
11 Limitation of floating point numbers Limited number of bits to represent mantissa and exponents.

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

View Full Document
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
Ask a homework question - tutors are online