1 / 23

Data

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. Storage Capacity.

buzard
Download Presentation

Data

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 cosc175/data

  2. 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 cosc175/data

  3. Numbering Systems cosc175/data

  4. Binary to Decimal Multiply the 1's in a binary number by their position values, then sum the products.  Exa.  1 1 0 1 02 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 ---- 2610 cosc175/data

  5. 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:. 100112 = 1910 cosc175/data

  6. 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 02 • ------ ------ ------- • 4 1 68 cosc175/data

  7. Octal to Binary • Start with the rightmost digit • Look up the binary equivalent (3 digits) • 5 38 • 101 0112 cosc175/data

  8. Binary to Hex • Start with the rightmost digit • group by 4 digits • Look up the hex equivalent  • 1 1 0 0 0 1 0 12 • -------- --------- • C 516 cosc175/data

  9. Hexadecimal to Binary Perform the grouping procedure in reverse. B 316 1011 00112 cosc175/data

  10. 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 cosc175/data

  11. 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 cosc175/data

  12. 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 cosc175/data

  13. cosc175/data

  14. 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 cosc175/data

  15. 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; intnumStudents; cosc175/data

  16. 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 cosc175/data

  17. 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 cosc175/data

  18. Declarations of numeric variables in C++ int test1; int test2; float avg; cosc175/data

  19. 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 cosc175/data

  20. 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” cosc175/data

  21. Logical Data •  Boolean • TRUE - yes •  FALSE - no •  used for decisions or tests bool isEmpty; cosc175/data

  22. 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; cosc175/data

More Related