home *** CD-ROM | disk | FTP | other *** search
/ TCE Demo 2 / TCE_DEMO_CD2.iso / demo_cd_.2 / mags / stosser / stoser05.arj / stoser05.msa / A / 46.PNE < prev    next >
Text File  |  1987-04-22  |  1KB  |  76 lines

  1.  
  2.           STOS BITS 'N PIECES
  3.  
  4.                    by
  5.  
  6.         Martin Cubitt July 1993
  7.  
  8.  
  9.  Many of you will find there are times
  10. when you are programming STOS when you 
  11. require to convert decimal to hexa-
  12. decimal and vice versa.
  13.  
  14.  The STOS manual shows the command HEX$
  15. (n) which converts the decimal value n
  16. to a hexadecimal string value, for
  17. example:
  18.  
  19.  print hex$(255)
  20.  
  21.  will result in $FF being printed on
  22. screen.
  23.  
  24.  The prefix $ is a computer standard to
  25. signify that the value given is in hexa-
  26. decimal format.
  27.  
  28.  Okay, so how do you convert a hexa-
  29. decimal number to a decimal one?
  30.  
  31.  Hmmm, I cannot find this in the manual.
  32. Well the answer is really quite simple.
  33.  Enter:
  34.  
  35.  print $FF
  36.  
  37.  and the computer will display 255.
  38.  
  39.  So to summarise, use H$=HEX$(n) to con-
  40. vert from decimal to hexadecimal and use 
  41. D=$n to convert from hexadecimal to
  42. decimal.
  43.  
  44.  The same is true with binary except
  45. that the prefix is %, not $.
  46.  
  47.  So the command:
  48.  
  49.  print bin$(5)
  50.  
  51.  will display %101
  52.  
  53.  and the command:
  54.  
  55.  print %101
  56.  
  57.  will display 5.
  58.  
  59.  Both HEX$(n) and BIN$(n) return string
  60. values, that is the values returned are
  61. NOT numbers but characters. So to store
  62. them you must use a string variable such
  63. as H$ or B$. Not that the prefix of $ or
  64. % will be stored in the string. This can
  65. be removed with the command:
  66.  
  67.  H$=hex$(255)-"$"
  68.  
  69.  or
  70.  
  71.  b$=bin$(255)-"%"
  72.  
  73.  
  74.  CUBITTM/STOS0003/190793
  75.  
  76.