0% found this document useful (0 votes)
15 views5 pages

1.4.1 Data Types

The document discusses various primitive data types including integers, floats, characters, strings, and Booleans. It also covers binary representation of positive and negative numbers, hexadecimal, floating point numbers, and character sets. Key topics include two's complement representation of negative integers in binary, normalization of floating point numbers, and Unicode addressing the limited character set of ASCII.

Uploaded by

harry.connor4615
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views5 pages

1.4.1 Data Types

The document discusses various primitive data types including integers, floats, characters, strings, and Booleans. It also covers binary representation of positive and negative numbers, hexadecimal, floating point numbers, and character sets. Key topics include two's complement representation of negative integers in binary, normalization of floating point numbers, and Unicode addressing the limited character set of ASCII.

Uploaded by

harry.connor4615
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Primitive Data Types:

Integer (int) Any positive/negative whole number. 6, 35, -12, 0


Real/Float Any positive/negative number with a decimal point/fractional part. 5.01, -80.8

Character A single character – letter, symbol, ‘number’. H, C, ‘7’, Σ

String (str) A collection of characters. “Hello, world!”, “1932”

Boolean Truth values associated with Logic & Boolean algebra. True (1), False (0)

Casting – Converting from one data type to another.

Represent Positive Integers in Binary (Base 2):


Bit – Single binary digit (1, 0)
=8+4+1 Byte – 8 bits
= 13 Nibble – 4 bits
MSB LSB

Represent Negative Integers in Binary:

1. Sign & Magnitude

2. Two’s Complement – Works by Making the MSB negative:


Flip all the bits of the positive binary number & add one.
E.g. 7 is 00000111. Flip all the bits gets you 11111000, adding one gives you 11111001.

Addition & Subtraction of binary integers:

Subtracting a number from another is the


same as adding a negative number in
two’s complement.
Hexadecimal (Base 16) – Simplifies long streams of bits that are difficult to understand:

Hexadecimal -> Binary: Hexadecimal -> Decimal:

Decimal -> Hexadecimal:

210/16 = 13r2 16 1
= D2 D 2

0 – POSITIVE exponent (point floated to the RIGHT)


Floating Point Numbers in Binary: 1 – NEGATIVE exponent (point floated to the LEFT)

0 – Positive mantissa
1 – Negative mantissa

This is a positive
mantissa so the left most
1 has a positive place
value.
This is a negative
mantissa so the left
most 1 has a negative
place value.

Convert Positive Denary Numbers into Floating Point Binary:

1. Calculate 0.25 in Pure Binary.

2. Reposition the binary point so it


occurs IMMEDIATELY to the left of
left most 1. Because it’s positive the
first bit must be a 0.

3. In order to get this binary point back


to its original position you would
need to float it 1 place to the left.

4. Convert the exponent into binary.

Convert Negative Denary Numbers into Floating Point Binary:

Note you could represent


-1.5 like this but for a
negative number, leadings
1. Calculate -1.5 in Pure Binary.
1s are as useless as leadings
0s in a positive number.
2. Reposition the binary point so that it
occurs IMMEDIATELY to the left of
the left most 0. Because its negative
the sign bit must be a 1.

3. In order to get this binary point back


to its original position you would
need to float it 1 place the right.

4. Convert the exponent into binary.


Normalisation – Floating point numbers are normalised to maximise precision for a given
mantissa. Normalised Form: POSITIVE – Start with 0 1, NEGATIVE – Start with 1 0.

1. Decide if you’re dealing with a


positive or negative number.

2. Reposition the point so it sits


IMMEDIATELY to the left of the left
most 1. A positive number must start
with 0 1.
3. Get rid of meaningless 0s on LHS & The point was moved 2 places to right, so
pad out RHS. you need to subtract 2 from the exponent.
4. Calculate NEW VALUE for the
exponent.

Floating Point Addition:


- Make sure both numbers are normalised.
- Make exponents the same (Make smaller exponent match the larger exponent OR
UNDO EXPONENT AND REWRITE WITHOUT).
- Add mantissas together.
- Normalise result if necessary (will change exponent).

Floating Point Subtraction:


- Make sure both numbers are normalised.
- Make exponents the same (Make smaller exponent match the larger exponent OR
UNDO EXPONENT AND REWRITE WITHOUT).
- If performing subtraction, negate the number to subtract (invert bits and add one).
- Add mantissas together.
- Normalise result if necessary (will change exponent)

Bitwise Manipulation and Masks:

Logical Shifts:
Left Logical Shift – Multiplication by two to the power of the number of places shifted.
E.g Shift Left by 3 of 10010110  10010110000.
Right Logical Shift – Division by two to the power of the number of places shifted.

Masks:
A mask can be applied to binary numbers by combining them with a logic gate.

AND has the effect of multiplying inputs.


Only the digits in the 2 numbers which are
both 1 result in a 1 after the mask has been
applied.
Character Sets – Defined list of characters/symbols that can be interpreted/understood by
a computer:

Each character represented by unique value, to map binary values to characters.

ASCII (American Standard Code for Information Interchange):


- Uses 8 bits to represent each character.
- A-Z = 65-90, a-z = 97-122. Also, codes for numbers & symbols.
- ASCII came into trouble when computers needed to represent other languages.
Unicode:
- Solves the problem of ASCII’s limited character set.
- Uses a varying number of bits allowing for over 1 million different characters (emojis,
different languages).

You might also like