Data types
Transcript of Data types
Defining The Problem & Planning Software
Solutions
Data Types
Syllabus
Data Types Data types used in solutions including:
Integer String Floating Point Boolean Date and Currency
Why are they needed?
321
Hi I am going to tell you about why computers
require data types and data structures.
Firstly, when we use a computer that is classified
as INPUT.
INPUT
This raw rata is converted into binary – machine code via the electronic signals on
the computers keyboard.
As you know this information needs to be
processed so information can be generated and
OUTPUTTED.
However, this data must be stored in similar categories
for processing.
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
So therefore we need data types to organise data for
processing.
Examples of Data
DATA
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.
How is data stored?
101001
1002
1003
1004
1005
Num1
Computer - Store 10 in 1001
Programmer – Num1 = 10
How is data stored?
10
12
1001
1002
1003
1004
1005
Computer - Store 12 in 1002
Programmer – Num2 = 12
Num2
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
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
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
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
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
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
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
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
Activity 1
DiscussionBinary Numbers are different for humans to comprehend. Why do you think octal and hexadecimal are preferred options.
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
Activity 3Decimal Binary Octal Hexadecimal
4510
10101112
758
3FC16
Data Types
The following are examples of common data types used: Integers Floating Point String Boolean Date and Times Currency
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
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.
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
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
Homework
Set 4B
Q1-10, 11, 12