Data Types / Binary Flashcards
primitive data type
a basic data type provided by the programming language as a basic building block
types of primitive data types (5)
- integer
- real/float
- boolean
- character
- string
denary
base 10 number. uses the combination of ten symbols to represent any number
binary
base 2 number. uses the combination of 2 symbols (0 or 1) to represent every number
hexadecimal
based 16 number. uses the combination of 16 symbols (10 numbers and 6 letters) to represent every number
why use hexadecimal?
- easier to read/ remember
- quicker to write/type
- less chance of making an error
- easy to convert
uses of hex
- define colours
- in MAC addresses
- in assembly language and machine code
integer
any positive or negative whole number e.g. 3, 0, -14
real (floating point)
a positive or negative number with a fractional component e.g. 0.002 or -1.98
character
Any single letter, symbol, number, character or control character
string
any combination of letters, symbols, numbers, characters or control characters e.g. Hello, £4.56
Boolean
Any true/ false data types which often represent logical situations
Sign magnitude most significant bit
represents + or -
+ = negative
- = positive
0.1
positive
1.0
negative
fixed point binary
positive of the binary point is fixed on the number line
by changing the position of the binary point you can…
increase the size of the number
increase the accuracy of the number
mantissa
the actual number you want to store
exponent
positive of the binary point is fixed on the number line
how to convert floating point binary to denary
1) First work out the denary number in the exponent which tells us that the binary point moves ‘n’ places to the right
2) Write out a new binary weighting line with the point in the right place and then convert into denary
Binary -> denary positive exponent
right
Binary -> denary negative exponent
left
in two’s complement the sign is stored in
the most significant bit
normalising a number
means that there is only one way to represent the number
advantage of normalisation
it stores the most accurate version of that number.
Bitwise manipulation
bitwise shifts and masks
Bitwise shifts can be used …
to change numbers quickly
Masks can be used …
to set and toggle specific bits in a larger sequence.
toggle
swap to the opposite
What is bitwise manipulation useful for?
- Compression Algorithms
- networks (protocols. routing packets)
- multiplication and division
What does a bitwise left shift do?
multiplies the number by 2.
What happens to bits falling off the end on a bitwise left shift?
If any bits fall off the end it is just lost and the empty place on the left is replaced with a 0
What does a bitwise right shift do?
divides the number by 2.
What happens to bits hat fall off the end with a bitwise right shift
If any bits fall off the end it is just lost and you back fill with 1s
how does arithmetic (signed) right shift work?
shift everything to the right and backfill the space with 1s
how does circular shifting work?
you shift either way and the left over bit circles back around to the beginning.
What is a mask?
A mask allows you to isolate, extract, toggle and set bit values in a sequence of bits.
Bitwise ANDing …
extracts a subset of the bits in a value
when the mask is a 1 it retains the value however when the mask is a 0 it outputs just 0s meaning only certain values are extracted.
Bitwise ORing …
sets a subset of the bits in the value
you use 1s where you want to set values and 0s when you want to leave them alone
Bitwise XORing…
toggles a subset of the bits in the value
when you use a 1 the bianry is toggled/ switched around and 0s there is no impact
When is Bitwise ANDing useful?
useful for TCP/IP and routing
toggle a subset of bits
Bitwise XORing
set a subset of bits
Bitwise ORing
extract a subset of bits
Bitwise ANDing
What does ASCII stand for
American Standard Code for Information Interchange
What are the two most common character sets?
ASCII and Unicode
What are character sets needed for?
needed so that a document which is made on one computer is still readable on another computer. Computers can have more than one character set installed.
What is a more complex data type called?
composite types
array
allows you to store multiple items of the same data type under a shared common name
subtract binary numbers
two complement one and then add
how to twos complement a number
from right to left move until you hit a 1. all the subsequent bits should be swapped.
How are character sets used to represent text?
When character in the set has a corresponding binary value which is a set number of bits. These are stored in a sequence that represents a word etc.
more bits in the mantissa…
improves the accuracy but reduces the range
more bits in the exponent…
improves the range but reduces accuracy
how to normalise a number:
- see how many places the binary point has to move so the number starts 01 or 10
- store this number in the exponent and then new format of the number in the exponent
normalising a negative binary number
back fill with 1s at the high end and 0s at the low end
normalising a positive binary number
back fill with 0s
normalising:
moving the point to the right
- exponent
normalising:
moving the point to the left
+ exponent
why is twos complement better than sign magnitude
it easy to complete calculations with twos complement
How does the size of the mantissa and exponent effect the number
the larger the mantissa the more accurate
the large the exponent the larger the range of numbers that can be represented