Download presentation
Presentation is loading. Please wait.
1
EPSII 59:006 Spring 2004
2
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
3
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
4
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).
5
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 == 128 == 255
6
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 * a2*102 + a1*101 + a0*100
7
Question What does Equal in decimal?
8
Solution = = 29
9
Hexadecimal Binary is a pain to work with because the representation is so long There are 16 possible combination of 4 binary digits
10
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
11
Question What is the octal code?
12
Answer a3a2a1a0 Octal = a3*83 + a2*82 + a1*81 + a0*80
13
Exercise Convert A9 to binary Convert to Hex
14
Solution Convert A9 to binary Convert to Hex D C
15
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 = states (216) => 64K Memory is arranged in bytes – each individual address points to the beginning of a byte.
16
How are variables stored?
Characters are stored as numbers: ASCII : ftp://dkuug.dk/i18n/WG15-collection/charmaps/ANSI_X Unicode over 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.
17
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
18
Other Variable Types Type unsigned positive Integers
4 (usually, but is really implementation-dependent) short integers 2 long 4 (usually)
19
Variable Type Storage Type Storage (bytes) Range of Values int 4
char 1 -128 to 127 float e-38 to e+38 double 8 e-308 to e+308
20
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));
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.