Numbers and Values in Objective-C and C Programming

14
Paul Solt iPhoneDev.tv Numbers The data behind our apps

Transcript of Numbers and Values in Objective-C and C Programming

Page 1: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

NumbersThe data behind our apps

Page 2: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Overview• Integers (27)

•printf()

•Floating-point numbers (3.14)

•Math libraries

Page 3: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Integers•char: ‘a’, ‘b’, ‘c’

•short: 32,000

•int: 2,000,000,000

•long: 9,000,000,000,000,000,000

•long long: 9,000,000,000,000,000,000

Page 4: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Integers•char: ‘a’, ‘b’, ‘c’ (8 bits = 1 byte)

•short: 32,000 (16 bits)

•int: 2,000,000,000 (32 bits)

•long: 9,000,000,000,000,000,000 (32 or 64 bits)

•long long: 9,000,000,000,000,000,000 (64 bits)

Page 5: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Overflow99999

99999

10000000

10000000

Page 6: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

printf

•Formatted text

•Tokens

• \n (i.e. newline or return)

%d int

%c char

%f float/double

%s char * (i.e. text)

%ld long

Page 7: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Math

8 + 4 * 2 = ?

(8 + 4) * 2 = ?

Page 8: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Integer Division

5 / 2 = ?5 % 2 = ?

Page 9: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Integer Division

5 / 2 = 25 % 2 = 1

Page 10: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Floating-point Numbers

•float: 3.14

•double: 3.141592653

Page 11: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Floating-point Numbers

•float: 3.14 (32 bits)

•double: 3.141592653 (64 bits)

Page 12: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Math Library

#include <stdlib.h> abs(-13); // absolute value #include <math.h> cos(60 * M_PI / 180.0); // radians

Page 13: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv

Review• Integers

•printf()

•Floating-point numbers

•Math libraries

Page 14: Numbers and Values in Objective-C and C Programming

Paul Solt iPhoneDev.tv