0% found this document useful (0 votes)
107 views

Data Types T1 Data Types, Binary and Hexadecimal

Uploaded by

booboo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

Data Types T1 Data Types, Binary and Hexadecimal

Uploaded by

booboo
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

Primitive data types,

OCR binary and


A Level hexadecimal
Unit 6
Computer Science
Data types
H446 – Paper 1

1
Objectives
• List and define primitive data types
• Represent positive integers in binary and
hexadecimal
• Convert between binary, hexadecimal and denary
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Primitive data types


• A primitive data type is one which is provided by a
programming language
• They include:
• integer a whole number such as 34, 0, -1, 567432
• real/float a number with a fractional part such as:
3.142, 7.0, -67.5
• Usually, a composite data type such as an array is
not considered to be a primitive data type
• Can you think of some more primitive data types?
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Primitive data types


• A primitive data type is one which is provided by a
programming language
• They include:
• integer a whole number such as 34, 0, -1, 567432
• real/float a number with a fractional part such as
3.142, -67.5
• Boolean can only take the value True or False
• character a letter, number or special symbol such as
“a”, “A”, “6”, “&”, %”
• string anything enclosed in quote marks, for example
“Jason”, “01798 158794”, “This is a string”
Primitive data types, binary and hexadecimal
Unit 6 Data Types

How are different data types


held?
• All data types are held in binary
• Without knowing what the data type is, it is not
possible to say what a particular bit pattern
represents
00101000 111110001 01010111 00100100
• This could be one integer, 4 integers, a real number,
a string, 4 characters,…
• or even a sound, a pixel or a tiny piece of a graphic
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Binary number system


• The binary number system uses only two digits,
0 and 1
• To understand how this works, it is helpful to look
first at the fundamentals of the denary or decimal
system, which uses digits 0..9
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Number symbols
• The denary number system uses a combination of
just ten symbols to represent any number
• Number systems are referred to by their base; that
is, the number of symbols used to construct values
• Denary is base 10 and the base may be referred to
as a subscript
• In denary the number 11, for example, may be written as 1110
• In binary, it would be written as 112 and in hexadecimal as
1116
• 1110, 112 and 1116 all represent different values
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Base 2
• Numbers which use base 2 Denary Binary
are commonly referred to as 1 1
2 10
binary numbers
3 11
• Can you see a pattern in the 4 100
binary values? 5 101
6 110
7 111
8 1000
9 1001
10 1010
11 1011
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Place value
• In any counting system, the position of the value
determines its contribution to the overall total

Baseposition 102 101 100

Place value 100 10 1

Number 1 8 3

Digit value 100x1 10x8 1x3

• Therefore 18310 represents the value of


one hundred, eight tens and three units
Primitive data types, binary and hexadecimal
Unit 6 Data Types

The binary system


• Binary works the same way, except the base used is
2 instead of 10

Baseposition 27 26 25 24 23 22 21 20
Place value 128 64 32 16 8 4 2 1
Number 1 0 1 1 0 1 1 1
Digit value 128x1 0 32x1 16x1 0 4x1 2x1 1x1

• Therefore 1 0 1 1 0 1 1 12 represents
128 + 32 + 16 + 4 + 2 + 1 which is equivalent to 18310
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Converting from denary


• The place value table is useful to aid conversion
from denary to binary
• Convert 15910 to binary

Place value 128 64 32 16 8 4 2 1

Number 1 0 0 1 1 1 1 1

1. Can 128 2. If it can, 3. If value used 4. Repeat


be used to use it by subtract from using value
make some setting bit starting value, from step 3
of 159? value to 1, eg. 159 – 128 = until nothing
(0 if not) 31 left
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Activity
• Complete Task 1 in Worksheet 1
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Hexadecimal – Base 16
• Number systems with bases above 10 often still use
0 to 9 but require extra symbols for values past 9
• An example of this is base 16 which is referred to as
the hexadecimal number system
• Hexadecimal uses letters for the values 10 to 15

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

0 1 2 3 4 5 6 7 8 9 ABCDEF
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Hexadecimal values
• The rules of place value work in the same way:

Baseposition 162 161 160


Place value 256 16 1
Number 3 F (or 15) 5
Digit value 256 x 3 16 x 15 1x5

• Therefore the equivalent of 3F516 in denary is


(256x3) + (16x15) + 5 = 768 + 240 + 5 = 101310
• What is A316 in denary?
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Denary to hex conversion


• Converting to two-digit hexadecimal numbers
• Divide the number by 16, and add the remainder

43 ÷ 16 = 2 remainder 11
11 = B
= 2B

• What is 2710 in hexadecimal?


Primitive data types, binary and hexadecimal
Unit 6 Data Types

Significant powers
• Work out the following powers of 2:

20 =
21 =
22 =
23 =
24 =
• Why is the answer to 24 significant?
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Significant powers
• Work out the following powers of 2:

20 = 1
21 = 2
22 = 4
23 = 8
24 = 16
• Why is the answer to 24 significant?
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Significance of 16
• 16 is the fourth power of 2
• This means that base 16 numbers can be translated
from 4 consecutive bits of a binary value
• This makes it simple to translate binary numbers into
hexadecimal values and back again
8 4 2 1 8 4 2 1

216 = 1 1 0 1 1 0 0 0
= D 8
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Hex colour codes

• The hex code for this colour is 36 4D B2


• What does this mean?
• How can you increase the amount of red,
using the hex code?
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Activity
• Complete Task 2 on Worksheet 1
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Why use hex?


• A hexadecimal value is much easier to read and
remember than a string of binary digits
• It is quicker to write or type, since a hex digit takes
up only one character, not four
• There is less chance of making an error when typing
hex characters than a string of 1s and 0s
• It is used to define colours, in MAC addresses, in
assembly languages and machine code
• It is very easy to convert to and from binary
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Plenary
• Denary numbers are easy to understand but they
are not easy to use in electronics
• Binary is simple to use with circuitry but is difficult to
read by humans
• Hexadecimal makes binary easier to read and easier
to transcribe (copy) accurately
Primitive data types, binary and hexadecimal
Unit 6 Data Types

Copyright

© 2016 PG Online Limited

The contents of this unit are protected by copyright.

This unit and all the worksheets, PowerPoint presentations, teaching guides and other associated files
distributed with it are supplied to you by PG Online Limited under licence and may be used and copied by you
only in accordance with the terms of the licence. Except as expressly permitted by the licence, no part of the
materials distributed with this unit may be used, reproduced, stored in a retrieval system, or transmitted, in any
form or by any means, electronic or otherwise, without the prior written permission of PG Online Limited.

Licence agreement

This is a legal agreement between you, the end user, and PG Online Limited. This unit and all the worksheets,
PowerPoint presentations, teaching guides and other associated files distributed with it is licensed, not sold, to
you by PG Online Limited for use under the terms of the licence.

The materials distributed with this unit may be freely copied and used by members of a single institution on a
single site only. You are not permitted to share in any way any of the materials or part of the materials with any
third party, including users on another site or individuals who are members of a separate institution. You
acknowledge that the materials must remain with you, the licencing institution, and no part of the materials may
be transferred to another institution. You also agree not to procure, authorise, encourage, facilitate or enable any
third party to reproduce these materials in whole or in part without the prior permission of PG Online Limited.

You might also like