Presentation is loading. Please wait.

Presentation is loading. Please wait.

Cosc175/data1 Data comprised of constants and variables information stored in memory Each memory location has an address Address - number identifying a.

Similar presentations


Presentation on theme: "Cosc175/data1 Data comprised of constants and variables information stored in memory Each memory location has an address Address - number identifying a."— Presentation transcript:

1 cosc175/data1 Data comprised of constants and variables information stored in memory Each memory location has an address Address - number identifying a location can do 2 things to data –read - doesn't change contents –write - replaces contents

2 cosc175/data2 Storage Capacity bit - 0 or 1, electrical states - on and off –nibble - 4 bits byte - 8 bits, holds 1 character word - number of bits handled as a unit for a particular computer system K,Kb - kilobyte –1024 bytes - approximately 1000 locations –640K - 640*1024 = 655,360 bytes –640K - approximately 640,000 locations Mb - Megabyte - 1024*1024, millions of bytes Gb - Gigabyte - 1 billion bytes

3 cosc175/data3 Numbering Systems Numbering systemBASEDigits Decimal100 - 9 Octal80 - 7 Hexadecimal160 – F Binary20 - 1

4 BinaryOctalHexDecimal 0000000 0001111 0010222 0011333 0100444 0101555 0110666 0111777 10001088 10011199 101012A10 101113B11 110014C12 110115D13 111016E14 111117F15 10000201016

5 cosc175/data5 Multiply the 1's in a binary number by their position values, then sum the products. Exa. 1 1 0 1 0 2 0 x 2^0 = 0 1 x 2^1 = 2 0 x 2^2 = 0 1 x 2^3 = 8 1 x 2^4 = 16 ---- 26 10 Binary to Decimal

6 cosc175/data6 Converting From Decimal to Binary use the division/remainder technique 1.Divide the number repeatedly by 2 and record the remainder of each division. exa. 2 | 19 ----- 2 | 9 ---> 1 ----- 2 | 4 ---> 1 ----- 2 | 2 ---> 0 ----- 2 | 1 ---> 0 ----- 0 ---> 1 2.Reverse:.10011 2 = 19 10

7 cosc175/data7 Binary to Octal Start with the rightmost digit group by 3 digits Look up the octal equivalent 1 0 0 0 0 1 1 1 0 2 ------ ------ ------- 4 1 6 8

8 cosc175/data8 Octal to Binary Start with the rightmost digit Look up the binary equivalent (3 digits) 5 3 8 101 011 2

9 cosc175/data9 Binary to Hex Start with the rightmost digit group by 4 digits Look up the hex equivalent 1 1 0 0 0 1 0 1 2 -------- --------- C 5 16

10 cosc175/data10 Hexadecimal to Binary Perform the grouping procedure in reverse. B 3 16 1011 0011 2

11 cosc175/data11 Variables and Constants constant –alphabetic or numeric value that never changes during processing –can be any data type –can also be used for something that may change at a later date –need only be changed in one place –Aids readability –const float PI = 3.14; –const float MD_TAX_RATE =.06; –Note, use caps for constants variable - value does change during process

12 cosc175/data12 variable names Corresponds to memory location or address Naming convention varies varies from language to language Alphanumeric,begin with alphabetic characters no spaces in variable names any number of characters meaningful names exa payRate hrsWorked

13 cosc175/data13 example solution that calculates payroll for a company: const string COMP_NAME = “COMPANY1”; const float OT_RATE = 1.5; string empName; float hoursWorked; float payRate; values change for each employee can use one program and modify each variable to process 1000 employees

14 cosc175/data14 Data TypesData setExamples Integer All whole numbers 3580, -90, 6 Float (or real) All real numbers 37.92, -8.3, 100.0 Character All letters, symbols, numbers, and special symbols 'A', 'a', '&','8' single quotes String Combination of more than one character "21093", "Mrs Smith" Double quotes BooleanTRUE, FALSEdone, valid

15 cosc175/data15 Numerical Data all types of numbers used in calculations use numerical data for values such as salary, hours not zip-code or social security number int float or double

16 integers whole numbers –positive or negative –counters - number of people or inventory What is the largest number stored in 32 bits? Sign bit int int num1; int num2; int numStudents; cosc175/data16

17 cosc175/data17 real numbers whole numbers plus the decimal part float or double precision - number of significant digits –number of digits visible in the number magnitude - size of the number measured by the power of ten –3.4598723 x 10.9 –8 significant digits, magnitude of 9 –348 million - 3 significant digits

18 cosc175/data18 precision precision varies with the computer greater the number of significant digits -> greater precision or accuracy the computer converts fractions to decimal and decimal to binary - > round-off errors for exa. 1/3 + 1/3 + 1/3.333333333 +.333333333 +.333333333 =.999999999 use smallest precision possible for efficiency

19 Declarations of numeric variables in C++ int test1; int test2; float avg; cosc175/data19

20 cosc175/data20 characters all letters, numbers, and special characters Declare character inputChar BCD - convert each digit into binary form (uses 4 bits) ASCII - American Standard Code for Information Interchange –7 bits –used for pc's –http://www.asciitable.com/ EBCDIC - Extended Binary Coded Decimal Interchange Code –8 bits –IBM mainframes

21 cosc175/data21 string set of characters + - concatenation - joins strings together –"4" + "4" = "44" use string for zip code - allows you to hold leading 0's Declare string zipCode zipCode = “21093”

22 cosc175/data22 Logical Data Boolean TRUE - yes FALSE - no used for decisions or tests bool isEmpty;

23 cosc175/data23 Declaring Data Types Variables must be declared before use. Declaration defines type, allocates space in memory. variable names - corresponds to address type name string studentName; float payPerHr ;


Download ppt "Cosc175/data1 Data comprised of constants and variables information stored in memory Each memory location has an address Address - number identifying a."

Similar presentations


Ads by Google