data types
TRANSCRIPT
![Page 1: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/1.jpg)
Defining The Problem & Planning Software
Solutions
Data Types
![Page 2: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/2.jpg)
Syllabus
Data Types Data types used in solutions including:
Integer String Floating Point Boolean Date and Currency
![Page 3: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/3.jpg)
Why are they needed?
321
![Page 4: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/4.jpg)
Hi I am going to tell you about why computers
require data types and data structures.
![Page 5: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/5.jpg)
Firstly, when we use a computer that is classified
as INPUT.
INPUT
![Page 6: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/6.jpg)
This raw rata is converted into binary – machine code via the electronic signals on
the computers keyboard.
![Page 7: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/7.jpg)
As you know this information needs to be
processed so information can be generated and
OUTPUTTED.
![Page 8: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/8.jpg)
However, this data must be stored in similar categories
for processing.
![Page 9: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/9.jpg)
All the data is filtered into categories for storage and
subsequent processing.
A B C1 55 7 8 90
22/3
/80$22.00
Integer Character String Date
![Page 10: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/10.jpg)
So therefore we need data types to organise data for
processing.
![Page 11: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/11.jpg)
Examples of Data
DATA
![Page 12: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/12.jpg)
How is data stored?
Data is stored as either a constant or a variable.
Current practices requires the use of symbolic names for the programmer i.e. Name, age NOT X, Y, Z.
However, each storage location has a memory address for the hardware to use.
![Page 13: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/13.jpg)
How is data stored?
101001
1002
1003
1004
1005
Num1
Computer - Store 10 in 1001
Programmer – Num1 = 10
![Page 14: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/14.jpg)
How is data stored?
10
12
1001
1002
1003
1004
1005
Computer - Store 12 in 1002
Programmer – Num2 = 12
Num2
![Page 15: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/15.jpg)
How is data stored?
10
12
22
1001
1002
1003
1004
1005
Computer – ADD 1001 to 1002 and STORE in 1003
Programmer – Total = Num1 + Num2
Total
![Page 16: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/16.jpg)
Number Representation
Data is raw facts entered into a computer. Examples include:
Words Numbers Dates Images
Regardless which data type is entered, the data can only be processed by the computer, if it is in BINARY
![Page 17: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/17.jpg)
Binary Number System
Basically, every piece of data can be represented by a series of bits (0 and 1)
Like the switches in electricity (off or on) Binary is usually written in sets of 8 bits Like decimal numbers, each place in binary
is equivalent to a value
![Page 18: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/18.jpg)
Binary Number SystemNumber 1 0 1 1 1
Binary Place 2 4 2 3 2 2 2 1 2 0
Binary Place Value 16 8 4 2 1
Binary Calculation 1 x 2 4 0 x 2 3 1 x 2 2 1 x 2 1 1 x 2 0
Binary Value 16 0 4 2 1
Binary Total = 16 + 4 + 2 + 1= 23
![Page 19: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/19.jpg)
Octal Number System
Basically, every piece of data can be represented by a series of digits (0, 1, 2, 3, 4, 5, 6, 7)
Like decimal numbers, each place in octal is equivalent to a value
![Page 20: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/20.jpg)
Octal Number SystemNumber 3 4 5 2 1
Octal Place 8 4 8 3 8 2 8 1 8 0
Octal Place Value 4 096 512 64 8 1
Octal Calculation 3 x 8 4 4 x 8 3 5 x 8 2 2 x 8 1 1 x 8 0
Octal Value 12 288 2 048 320 16 1
Octal Total = 12 288 + 2 048 + 320 + 16 + 1= 14 673
![Page 21: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/21.jpg)
Hexadecimal Number System
Basically, every piece of data can be represented by a series of digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F)
Like decimal numbers, each place in hexadecimal is equivalent to a value
![Page 22: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/22.jpg)
Hexadecimal Number SystemNumber 1 2 4 A C
Hex Place 16 4 16 3 16 2 16 1 16 0
Hex Place Value 65 536 4 096 256 16 1
Hex Calculation 1 x 16 4 2 x 16 3 4 x 16 2 10 x 16 1 12 x 16 0
Hex Value 65 536 8 192 1 024 160 12
Hex Total = 65 536 + 8 192 + 1 024 + 160 + 12= 74 924
![Page 23: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/23.jpg)
Activity 1
DiscussionBinary Numbers are different for humans to comprehend. Why do you think octal and hexadecimal are preferred options.
![Page 24: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/24.jpg)
Activity 2
1. Convert the following binary numbers into decimal: 1110 1001 110011100110 110011111100
2. Convert the following decimal numbers into binary: 32 68
1. 1566 9999
![Page 25: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/25.jpg)
Activity 3Decimal Binary Octal Hexadecimal
4510
10101112
758
3FC16
![Page 26: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/26.jpg)
Data Types
The following are examples of common data types used: Integers Floating Point String Boolean Date and Times Currency
![Page 27: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/27.jpg)
Activity 4DATA TYPE DESCRIPTION EXAMPLES
Integer 50-487
Floating Point 2.764-67665.32.3 x 108
String CatDaggy2Eggplant
Boolean True FalseYesNo
Date 16/1/20064th June 2001
Currency $5.84-$58.97$1005.46
![Page 28: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/28.jpg)
Variables and Constants
A variable is a meaningful name given to something stored in memory that changes
The opposite to a variable is a CONSTANT Example:
Adding up the cost of 10 items, bought at the shops. The value called Total changes as each items cost is added. Total is therefore a variable.
Calculating the value of the GST. We know that GST Percentage is always 10% of the total. This makes GST Percentage a constant and the GST Value a variable.
![Page 29: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/29.jpg)
Naming Variables The variable name should reflect the data it contains ie Name,
Age, Address The variable should always be written as 1 word. If the name is
more than 1 word, show each new word with a capital letter ie FirstName, DateOfBirth
Most programming languages require variables to be declared and initialised (set to 0)
Hungarian notation dictates that each variable is prefixed with a mnemonic indicating what data type the variable holds ie intAge says that the variable is an integer that holds the age of the person while strName says that the variable is a string that holds the name of the person
![Page 30: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/30.jpg)
Activity 5Analyse the script below and highlight 1 constant and 2 variables. Identify the data types of the constant and variables.
BEGINGet MaxRepeat
Get AgeIF Age < Max then
Access = FalseELSE
Access = TrueENDIFPrint Access
UNTIL Age > MaxEND
![Page 31: Data types](https://reader035.vdocument.in/reader035/viewer/2022070317/556d08b7d8b42ad34f8b4a5d/html5/thumbnails/31.jpg)
Homework
Set 4B
Q1-10, 11, 12