Thursday, 18 October 2007

PHP

Today we started on PHP : Hypertext Preprocessor



PHP is a powerful server-side scripting language for creating dynamic and interactive websites



Variables in PHP are used to store values, like text,numbers or arrays. A variable which has been stored can be used over and over again.
Variables in PHP start with "$"

- $variable_name = value;

With PHP, a variable doesn't have to be declared as "string" or "int" as PHP can identify what type a variable is when it is called.

---

Variable Naming Rules
  • A variable name must start with a letter or an underscore "_"
  • A variable name can only contain alpha-numeric characters and underscores (a-Z, 0-9, and _ )
  • A variable name should not contain spaces. If a variable name is more than one word, it should be separated with underscore ($my_string), or with capitalization ($myString)

Friday, 5 October 2007

Task 29

Normalise these two positive numbers :

a) 0000 0001 0100 0111.

Mantissa : 0000 0001 01
Decimal : 0.000000101
Decimal : 0.101000000

Exponent : 000111 = 7 in denary.
To get back to the original we must move the decimal point 6 places to the left.
So, I subtract 6 from the current exponent.
The new Exponent becomes : 000001

Putting this back together, I get :
0101000000000001

b) 0000 0111 0000 1011

Mantissa : 0000 0111 00
Decimal : 0.000011100
Decimal 0.111000000

Exponent : 001011 = 11 in denary.
To get back to the original mantissa, we must move the decimal place 4 places to the left.
Therefore, I need to subtract 4 from the Exponent, leaving me with 7.
The new Exponent : 000111

Putting this back together, I get :

0111000000000111

Task 28

Normalise these numbers :

a) 0.45 x 10^6

b) 0.6 x 10^5

c) 0.487 x 10^2

Task 27

A two-byte floating point numberin gsystem uses 10 places for the mantissa and 6 for the exponent. Convert the number -11.125 into a normalised floating-point number by filling in the following table :

Step 1 : 11.125 in binary is 1011.001

Step 2 : Mantissa : 0001011.001

Step 3 : 2s complement : 1110100.111

Step 4 : Normalised Form : 1.001110000

Step 5 : The decimal place needs to be moved 2 places to the
left.

Step 6 : The exponenent : 111110

Step 7 : 1001 1100 0011 1110

Task 26

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert thenumber -8.5 into a normalised floating-point number by filling in the following table:

Step 1 : 8.5 in binary is : 1000.1

Step 2 : Mantissa : 000001000.1

Step 3 : 2s complement : 111110111.1

Step 4 : Normalised form : 1.011110000

Step 5 : Needs to be moved 4 places to the left.

Step 6 : The exponent is therefore 111100 = -4

Step 7 : The final answer is : 1011 1100 0011 1100

Thursday, 4 October 2007

Task 25

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number 1011 1111 1111 1111 into decimal by filling in the following table :

Step 1 : The number is negative because it starts with a 1.

Step 2 : The mantissa is : 1.011111111

Step 3 : The mantissa in Negative Binary : -(0.100000001)

Step 4 : The exponent is negative because it starts with a 1.

Step 5 : Exponent = 111111. Negative Binary = -(000001)

Step 6 : The decimal point in the mantissa must now be moved
1 place to the left.
Step 7 : The mantissa now becomes : -(0.0100000001)
Step 8 : The mantissa stays the same : -(0.0100000001)
Step 9 : Denary : 0.250976562

Task 24

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number 1010 0110 1000 0111 into decimal by filling in the following table :

Step 1 : This number is negative because it begins with a 1.

Step 2 : Mantissa : 1.010011010

Step 3 : -(0.101100110)

Step 4 : The exponent is : 000111 = 7

Step 5 : The decimal point must now be moved 7 places to the
right.

Step 6 : New Mantissa : -(01011001.10)

Step 7 : Removing unnecessary 0's : -(1011001.1)

Step 8 : Denary : -(89.5) or simply -89.5

Task 23

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number 1010 1100 0000 0011 into decimal by filling in the following table :


Step 1 : It begins with a 1

Step 2 : The mantissa is : 1.010110000

Step 3 : Negative Binary : -(0.101010000)

Step 4 : The exponent is : 000011

Step 5 : Decimal Point must be moved 3 places to the right.

Step 6 : The mantissa now becomes : -(1010.110000)

Step 7 : Removing unnecessary zeros gives : -(1010.11)

Step 8 : Denary : -(10.75) or simply -10.75

Task 22

A one-byte floating point numbering system uses 5 places for the mantissa and 3 for the exponent. Convert the number -4.0 into a normalised floating-point number by filling the following table.

Step 1 : 4.0 in binary : 100

Step 2 : Mantissa : 00100

Step 3 : 2s Complement : 11100

Step 4 : Normalised : 111.00

Step 5 : Proper Normalised : 1.0000

Step 6 : Decimal place needs to be moved 4 to right to get the pre-normalised form.

Step 7 : The exponent is therefore : 100

Step 8 : Final answer : 10000100

Task 21

A one-byte floating-point numbering system uses 5 places for the mantissa and 3 for the exponent. Convert the number -1.5 into a normalised floating-point number by filling in the following table :

Step 1 : 1.5 in binary : 1.1

Step 2 : Mantissa : 0001.1

Step 3 : 2s Complement: 1110.1

Step 4 : Normalised : 111.01

Step 5 : Proper Normalised : 1.0100

Step 6 : The decimal point needs to be moved 1 place to the
right

Step 7 : Exponent is : 001

Step 8 : 10100001

Task 20

A one-byte floating-point numbering system uses 5 places for the mantissa and 3 for the exponent. Convert the number 10011111 into decimal by filling in the following table :

Step 1 : The number begins with a 1.
Step 2 : Mantissa : 1.0011
Step 3 : Mantissa as Negative Binary : -(0.1101)
Step 4 : Exponent = 111
Step 5 : The decimal place in the mantissa must now be moved 1 place to the left.
Step 6 : New Mantissa : -(0.01101)
Step 7 : Removing extra 0's : -(0.01101)
Step 8 : Denary : -(0.40625) or simply 0.40625.

Task 19

A one-byte floating-point numbering system uses 5 places for the mantissa and 3 for the exponent. Convert the number 10111010 into decimal by filling in the following table :

Step 1 : It begins with a 1.

Step 2 : 1.0111

Step 3 : -(0.1001)

Step 4 : 010

Step 5 : The decimal point in the mantissa must now be moved
2 places to the right.

Step 6 : New Mantissa : -(010.01)

Step 7 : Removing 0's : -(10.01)

Step 8 : Denary : -(2.25) or simply -2.25.

Task 18

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number 2.75 into a normalised floating-point number using the following table to guide you.

Step 1 : Converting 2.75 gives us 10.11

Step 2 : 0.101100000

Step 3 : The decimal place needs to be moved 2 places to the right.

Step 4 : 000010

Step 5 : Final Floating-Point number : 0101 1000 0000 0010


Task 17

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number 12.5 into a normalised floating-point number using the following table to guide you.

Step 1 : 12.5 as a fixed-point number is 1100.1

Step 2 : 0.110010000

Step 3 : Needs moved 4 places to the right.

Step 4 : 000100

Step 5 : 0110 0100 0000 0100

Task 16

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number 0100 0000 0011 1101 into decimal by filling in the following table:

Step 1 : The first bit is a 0.

Step 2 : 0.100000000

Step 3 : The first bit is a 1.

Step 4 : -3

Step 5 : 3 places to the left.

Step 6 : 0.000100000000

Step 7 : 0.0001

Step 8 : 1/16

Task 15

A two-byte floating-point numbering system uses 10places for the mantissa and 6 for the exponent. Convert the number 0110 0001 1000 0110 into decimal by filling in the following table:

Step 1 : The first bit is a 0.

Step 2 : 0.110000110

Step 3 : The first bit is a 0.

Step 4 : 6

Step 5 : The decimal place must be moved 6 places to the right.

Step 6 : 0110000.110

Step 7 : 110000.11

Step 8 : 48.75

Task 14

A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number 0111 1010 0000 0101 into decimal by filling in the following table:

Step 1 : The first bit is a 0.
Step 2 : 0.111101000
Step 3 : The first bit is a 0.
Step 4 : Denary Equivalent : 5
Step 5 : The Decimal place must be moved 5 places to the right.
Step 6 : 011110.1000
Step 7 : 11110.1
Step 8 : 30.5

Task 13

A one-byte floating-point numbering system uses 5 places for the mantissa and 3 for the exponent. Convert the number 1.5 into a normalised floating-point number using the following table to guide you.

Step 1 : 1.1
Step 2 : 0.1100
Step 3 : 1 Place to the right.
Step 4 : 001
Step 5 : 01100001

Task 12

A one-byte floating-point numbering system uses 5 places for the mantissa and 3 for the exponene. Convert the number 2.25 into normalised floating-point number using the following table to guide you.

Step 1: 10.01
Step 2: 0.1001
Step 3: 2 Places to the right
Step 4: 010
Step 5: 01001010

Task 11

A one-byte floating-point numbering system uses 5 places for the mantissa and 3 for the exponent. Convert the number 01110111 into decimal by filling in the following table:

Step 1 : The first bit is a 0.
Step 2 : The Mantissa: 0.1110
Step 3 : Negative because it starts with a 1
Step 4 : Denary Equivalent of 111 = -1
Step 5 : The Decimal Place must be moved 1 place to the left because the Exponent = -1
Step 6 : Mantissa: 0.01110
Step 7 : New Mantissa: 0.0111
Step 8 : Final Denary Value: 0.475 or 7/16

Wednesday, 3 October 2007

Task 10

A one-byte floating point numbering system uses 5 places for the mantissa and 3 for the exponent. Convert the number 01100011 into decimal by filling in the following table :

Step 1 : I know this because the left most bit is 0
Step 2 : Mantissa : 0.1100
Step 3 : It starts out with a 0.
Step 4 : 011 = 3 in Denary
Step 5 : The deimal place must be moved 3 places to the right.
Step 6 : Mantissa : 0110.0
Step 7 : New Mantissa :110
Step 8 : Final Number : 6

Task 8 + 9

Task 8. Convert these fixed-point numbers into denary fractions using the above method:
a) 01111100 : 7 1/2
b) 00000100 : 1/2
c) 11000001 : 24 1/8

Task 9. Convert these denary numbers into binary using the fixed-point numbering system:
a)4.75 : 00100110
b)10.5 : 01010100
c)7.25 : 00111010
d)1.125 :00001001

Task 6 + 7

Task 6. Convert these 2s complement numbers into their denary values. Show your working.
a)10001 : -15
b)11000 : -8
c)00010: 2
d)01000 : 8
e)11110 : -2
f)01110 : 13

Task 7. Convert the following 7 bit 2s complement binary numbers into decima;. Show your working.

a) 1000100 : -60
b) 1011000 : -40
c) 0110001 : 49

Task 4 - 5

Task 4- How would you represent
a) -4
11100

b) -11
10101

c) -2
11110

Task 5- Using the above method and showing your working, convert
a)-12 into a 2s complement number
11100

b)-14 into a 2s complement number
11110

c)-1 into a 2s complement number
11111

Tasks 1-3

Task 1: Suppose you had 3 bits to represent 2s Complement Numbers.
a) What is the weighting of each bit?
[-4],[2],[1]

b) What is the largest number that can be represented?
3

c) What is the smallest number?
-4

Task 2: Suppose you had 7 bits to represent 2s complement number.
a) What is the weighting of each bit?
[-64],[32],[16],[8],[4],[2],[1]

b) What is the largest number that can be represented?
63

c) What is the smallest number?
-64

Task 3: How would you represent:
a)4
00100

b) 8
01000

c) 11
01111