{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

09+-+Data+Types+-+Full

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

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

Engineering 101 Data Types

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

View Full Document
Quote of the Day - Voltaire Judge people by their questions rather than by their answers.
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?

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

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

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

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

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

View Full Document
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
Data Encoding Bytes Meaning 11001110 10101010 11110000 10100101 11111111 11001110 11001110 Hail! to the victors valiant Hail! Hail!

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

View Full Document
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
Base 2 is a number system like  base 10 456,347

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

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

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

View Full Document
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
Base 2 is a number system like  base 10 110001 1 x  25  + 1 x  24  + 0 x  23  +

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 ]}