抖阴社区

Data types

15 0 0
                                    

Signed integers

 Signs and magnitude

First bit (Most Significant Bit) tells you the sign

1=negative, 0=positive 

1=negative, 0=positive 

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.


Two's compliment 

 E.g. -106

106=01101010

Flip the bits (one's complement):

10010101

Add 1 (two's complement):

10010110 

With two's complement, you can do calculations easier, as the MSB is the same data type

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

With two's complement, you can do calculations easier, as the MSB is the same data type. If you have 2 numbers, with one being a negative number in two's complement, you can add or subtract them to get the answer. Adding could result in an overflow, but since that is ignored it still works out. 

Example: 45-10

45= 00101101, -10= 11110110

00101101 + 11110110 = (1)00100011, as 1 is overflow it equals 35

Points

Fixed point

Fixed point

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

e.g. 1.75=

Floating Point

Oops! This image does not follow our content guidelines. To continue publishing, please remove it or upload a different image.

Floating Point


Exponent- the power to which the number in the mantissa is raised to

Mantissa- the part of the floating point number that represents the significant digits of that number

Mantissa*2^exponent

If you increase the bits of the mantissa, it increases the precision. Range isn't increased as with exponents you can have as many zeroes as you want

With exponents you can represent very big numbers and very small numbers 

E.g 01101 010

0.1101, shift 2 places to the left (or point 2 to the right):

011.01= 3.25 

Normalisation

How to know if something is normalised:

Positive num: mantissa starts with 01

Negative num: mantissa starts with 10 


Binary Arithmetic

This works in a similar way to column addition and subtraction, but of course in base 2. This means 1+1 is 10 (the 1 is carried), 1+0=1 and 0+0=0. Also for subtraction, 1-1=0, 0-0=0, and 1-0=1. Also, 0-1=-1, but like you would in column subtraction, unless you've forgotten how to do that (which I wouldn't blame you for as I think the last time it was covered for me was in year 4), you need to 'borrow' (steal) the the nearest 1 from the leftest column.

Computer Science Reviews (A level)Where stories live. Discover now