09+-+Data+Types+-+Full

09+-+Data+Types+-+Full - Engineering101 DataTypes...

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

View Full Document Right Arrow Icon
Engineering 101 Data Types
Background image of page 1

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

View Full DocumentRight Arrow Icon
Quote of the Day - Voltaire Judge people by their questions rather than by their answers.
Background image of page 2
Two Important Halves of  Computer Programming n Execution Control n Sequence n Selection n Iteration n Data Representation n How do we structure the data that we are acting  on?
Background image of page 3

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

View Full DocumentRight Arrow Icon
Data Types n Definition n a set of possible values  n plus , a set of legal operations on those values  n For example ( int ): n Integers within a given range n Operations: addition ( + ), subtraction ( - ), etc.
Background image of page 4
Mixed-Type Expressions n Even when binary operators are defined for  operands of the same type, you can often apply  them to different (mixed) types. n For example, arithmetic operators: n 53 + 26.2 n 53 / 26.2 n 26.2 - true  n To evaluate, the more restricted operand is  promoted   to the type of the other: bool   int   double
Background image of page 5

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

View Full DocumentRight Arrow Icon
Type Coercion n Coercion n The implicit (automatic) conversion of a value from one  data type to another n Coercion may apply when: n Evaluating a mixed-type expression n Assigning a value double myDub = 3; int myInt = 24.9; double avg = 39/5; n Passing a value to a routine n Returning a value from a function promoted to 3.0 demoted to 24 promoted to result of the integer division (i.e. 7.0)
Background image of page 6
Type Casting n Cast n The explicit conversion of a value from one data type to  another n Syntax of cast operation:      T ( expr ) n Evaluates expr, converts to type T int(24.9) int(x+0.5) double(39)/5 n Explicit cast often recommended for clarity, even when  coercion would apply 24 (just takes whole part) rounds to nearest int (if x positive) 7.8
Background image of page 7

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

View Full DocumentRight Arrow Icon
Data Representation n All data inside the computer is represented by bits. n Bits can have only two values 0 or 1. n 4 bits make a  nibble n 8 bits make a  byte 11001010 10101011
Background image of page 8
Data Encoding Bytes Meaning 11001110 10101010 11110000 10100101 11111111 11001110 11001110 Hail! to the victors valiant Hail! Hail!
Background image of page 9

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

View Full DocumentRight Arrow Icon
How many things can you encode  with a byte (8 bits)? n Each bit allows two possibilities. 1 bit: 0 1 (2 things) 2 bits:   00   01    10    11 (4 things) 3 bits:   000 001 010 011 100 101 110 111 (8 things) n bits: 2n   things 8 bits: 256 things
Background image of page 10
Base 2 is a number system like  base 10 456,347
Background image of page 11

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

View Full DocumentRight Arrow Icon
Base 2 is a number system like  base 10 456,347 100000 105 10000 104 1000 103 100 102 10 101 1 100 4 5 6 3 4 7
Background image of page 12
Base 2 is a number system like  base 10 456,347 4 x  105  + 5 x  104  + 6 x  103  +  3 x  102  + 4 x  101  + 7 x  100   100000 105 10000 104 1000 103 100 102 10 101 1 100 4 5 6 3 4 7
Background image of page 13

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

View Full DocumentRight Arrow Icon
Base 2 is a number system like  base 10 110001 1 x  25  + 1 x  24  + 0 x  23  +  0 x  22  + 0 x  21  + 1 x  20   32 25 16 24 8 23 4 22 2 21 1 20 1 1 0 0 0 1
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 53

09+-+Data+Types+-+Full - Engineering101 DataTypes...

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

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