home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / games / gamesuite / !Amnesia / AmsHelp / StartHere < prev    next >
Text File  |  1995-01-29  |  3KB  |  100 lines

  1. Start Here - Amnesia - Version 1.00
  2. ===================================
  3.  
  4. This file contains information for the inexperienced programmer about
  5. entering numbers in binary and hexadecimal.  If you already know how to do
  6. this, move to the Basics document.
  7.  
  8. One thing I will say to experienced users is BE CAREFUL WHEN USING << IN
  9. BASIC.  It has a low priority, so 1 + 1 << 5 is evaluated as (1+1)<<5, and
  10. worse still X AND 1<<3 is evaluted as (X AND 1) << 3.  Use brackets like X
  11. AND (1<<3).
  12.  
  13. Binary
  14. ------
  15.  
  16. Computers work with binary numbers - zeroes and ones.  To use Amnesia you
  17. need to know a bit about how binary numbers work.
  18.  
  19. As we move from right to left in a binary number, each figure is worth double
  20. the one to the right of it, so
  21.  
  22. Binary   |   Decimal equivalent
  23.  
  24.       1         1    
  25.      10         2 
  26.     100         4
  27.    1000         8  
  28.   10000        16   
  29.  100000        32
  30.      
  31.  and so on....
  32.  
  33. Each of the zeroes or ones in a binary number is a 'bit'.  The bit on the far
  34. right is called the least significant bit, bit zero, or the LSB, and the bit
  35. on the far left is the most significant bit (MSB).  Just about all numbers
  36. you’ll encounter when programming your Acorn computer are 32 bits long, so
  37. the MSB is bit 31.
  38.  
  39. In BASIC we can enter numbers in various ways.
  40.  
  41. %100000     : direct binary
  42. 1<<5        : a number and a shift value
  43. 32          : the decimal equivalent
  44. &20         : the hexadecimal equivalent
  45.  
  46. Shift values are useful when using Amnesia.  The << symbol shifts a number a
  47. certain number of binary places to the left. So
  48.  
  49. %11011 << 3 = %11011000
  50.  
  51. Equivalent to 27 << 3 = 216 in decimal
  52.  
  53. BASIC will convert between binary and other forms for you.  Try
  54.  
  55. PRINT %11011
  56. PRINT %11011 << 3
  57.  
  58. You may have noticed that <<3 is equivalent to multiplying by 8, just as <<4
  59. is equivalent to multiplying by 16, and <<5 multiplying by 32 etc.
  60.  
  61. Hexadecimal is useful as it's easy to convert to and from binary.  All you
  62. need to know are the 16 numbers and letters in binary.
  63.  
  64. 0000 = &0,  0001 = &1,   0010 = &2,  0011 = &3,     
  65. 0100 = &4,  0101 = &5,   0110 = &6,  0111 = &7,     
  66. 1000 = &8,  1001 = &9,   1010 = &A,  1011 = &B,     
  67. 1100 = &C,  1101 = &D,   1110 = &E,  1111 = &F.
  68.  
  69. Then you can chop up a binary number like this.
  70.  
  71. %01100100011101010110001101010001
  72.  
  73. splits up as    
  74.  
  75. %0110 0100 0111 0101 0110 0011 0101 0001
  76.  
  77. whis equals
  78.  
  79. &64756351
  80.  
  81. by exchanging each four binary digits for one hexadecimal digit.
  82.  
  83. So, when the Amnesia help files talk about using bit 11, you’ll know that you
  84. can enter that as any of %100000000000, 1<<11, &800, or 2048.
  85.  
  86. Try experimenting in BASIC.  Here are some type of commands to use.
  87.  
  88. A=%11010101    let A= a number in binary
  89. A=&FC0         let A= a number in hexadecimal
  90.  
  91. PRINT ~A       Print out A in hexadecimal
  92.  
  93. and the exotic
  94.  
  95. *Eval 16_FC0
  96. *Eval 36_ANDY
  97.  
  98. *Eval will convert any base up to base 36 into decimal!  Use 16_ for hex and
  99. 2_ for binary.
  100.