home *** CD-ROM | disk | FTP | other *** search
- Start Here - Amnesia - Version 1.00
- ===================================
-
- This file contains information for the inexperienced programmer about
- entering numbers in binary and hexadecimal. If you already know how to do
- this, move to the Basics document.
-
- One thing I will say to experienced users is BE CAREFUL WHEN USING << IN
- BASIC. It has a low priority, so 1 + 1 << 5 is evaluated as (1+1)<<5, and
- worse still X AND 1<<3 is evaluted as (X AND 1) << 3. Use brackets like X
- AND (1<<3).
-
- Binary
- ------
-
- Computers work with binary numbers - zeroes and ones. To use Amnesia you
- need to know a bit about how binary numbers work.
-
- As we move from right to left in a binary number, each figure is worth double
- the one to the right of it, so
-
- Binary | Decimal equivalent
-
- 1 1
- 10 2
- 100 4
- 1000 8
- 10000 16
- 100000 32
-
- and so on....
-
- Each of the zeroes or ones in a binary number is a 'bit'. The bit on the far
- right is called the least significant bit, bit zero, or the LSB, and the bit
- on the far left is the most significant bit (MSB). Just about all numbers
- you’ll encounter when programming your Acorn computer are 32 bits long, so
- the MSB is bit 31.
-
- In BASIC we can enter numbers in various ways.
-
- %100000 : direct binary
- 1<<5 : a number and a shift value
- 32 : the decimal equivalent
- &20 : the hexadecimal equivalent
-
- Shift values are useful when using Amnesia. The << symbol shifts a number a
- certain number of binary places to the left. So
-
- %11011 << 3 = %11011000
-
- Equivalent to 27 << 3 = 216 in decimal
-
- BASIC will convert between binary and other forms for you. Try
-
- PRINT %11011
- PRINT %11011 << 3
-
- You may have noticed that <<3 is equivalent to multiplying by 8, just as <<4
- is equivalent to multiplying by 16, and <<5 multiplying by 32 etc.
-
- Hexadecimal is useful as it's easy to convert to and from binary. All you
- need to know are the 16 numbers and letters in binary.
-
- 0000 = &0, 0001 = &1, 0010 = &2, 0011 = &3,
- 0100 = &4, 0101 = &5, 0110 = &6, 0111 = &7,
- 1000 = &8, 1001 = &9, 1010 = &A, 1011 = &B,
- 1100 = &C, 1101 = &D, 1110 = &E, 1111 = &F.
-
- Then you can chop up a binary number like this.
-
- %01100100011101010110001101010001
-
- splits up as
-
- %0110 0100 0111 0101 0110 0011 0101 0001
-
- whis equals
-
- &64756351
-
- by exchanging each four binary digits for one hexadecimal digit.
-
- So, when the Amnesia help files talk about using bit 11, you’ll know that you
- can enter that as any of %100000000000, 1<<11, &800, or 2048.
-
- Try experimenting in BASIC. Here are some type of commands to use.
-
- A=%11010101 let A= a number in binary
- A=&FC0 let A= a number in hexadecimal
-
- PRINT ~A Print out A in hexadecimal
-
- and the exotic
-
- *Eval 16_FC0
- *Eval 36_ANDY
-
- *Eval will convert any base up to base 36 into decimal! Use 16_ for hex and
- 2_ for binary.
-