Monday, 22 October 2007

PHP

Basics:

The PHP portion of code looks like this:
< ? php
? >


Each line of code is ended with " ; "

To declare a variable with PHP you declare it as you need it. This is done with a " $ "

Example: $txt = "Hello World!";
PHP will automatically assign the variable a type: string, integer etc.

Putting a (.) into a line of code will concat two variables. Example:
< ? php
$txt1="Hello World";
$txt2="1234";
echo $txt1 . " " . $txt2;
? >

The output of the code above will be:

Hello World 1234


Other Functions:
Strlen: finds string length
echo strlen("Hello world!");
Strpos: finds specified string in another string:
< ? php
echo strpos("Hello world!","world");
? >
The output of the code above will be: 6

Wednesday, 17 October 2007

Petrol Pumps (ticking display)

To get the ticking display to display the numbers in order instead of from left to right, I had to make sure the display always used three digits in processing. I used this code:

totalvalues = totalvalues + 1
Label1.Text = totalvalues

If Label1.Text.Length = 1 Then
Label1.Text = ("00") + Label1.Text
ElseIf Label1.Text.Length = 2 Then
Label1.Text = ("0") + Label1.Text
End If

Where "Label1" is the value of the petrol and it is this value to be displayed.
(this is on the tick event of the timer).

Monday, 15 October 2007

Binary worksheets.

Examples:

2's Complement: If first digit is "1", the number it represents is negative.

E.G: [4 2 1]
2's = 1 0 1 This means that the first digit in the binary represents -4.

This equation will be (-4) + 1 = -3

Mantissa and exponent:

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

Normalising:
A two-byte floating-point numbering system uses 10 places for the mantissa and 6 for the exponent. Convert the number -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