Using Octal in PE6

Morning folks,

Just a very quick question - does the PICAXE Editor support the Octal numbering system? Just personal preference, given that it's base-8... useful for an 8-bit microcontroller... Just can't find reference to it in the documentation

Cheers!
 

hippy

Technical Support
Staff member
PE6 doesn't support octal numbering natively but if you really wanted to include octal numbers in your program you could handle numbers up to 37777 using macros -
Code:
#Macro SetOctal(var,n)
  w11 = n
  Gosub Do_SetOctal
  var = w12
#EndMacro

#Macro SerOct(n)
  w11 = n
  Gosub Do_SerOctal
#EndMacro

Test:
  SetOctal(w2,377)
  SerTxd( "Octal 377 = ", #w2, TAB, "Octal = " )
  SerOct( w2 )
  SerTxd( CR, LF )
  End

Do_SetOctal:
  w12 = 0
  w13 = 1
  Do While w11 > 0
    w12 = w11 // 10 & 7 * w13 + w12
    w11 = w11 /  10
    w13 = w13 * 8
  Loop
  Return

Do_SerOctal:
  w13 = $8000
  Do While w13 > w11 And w13 > 1
    w13 = w13 / 8
  Loop
  Do
    w12 = w11 / w13 & 7 : SerTxd( #w12)
    w13 = w13 / 8
  Loop Until w13 = 0
  Return
  Return
 
Last edited:

Technical

Technical Support
Staff member
If you turn off the preprocessor you can unofficially use this. Octal has been in the compiler as a hidden test mode for 20 years, but can't remember anyone ever asking before!

Code:
do
    let b1 = '\17'
loop
 

Aries

New Member
I started my computing career with the Univac 1108, which had a 36-bit word. It used octal for its "internal" numbers, which made sense, because a word held 12 octal digits. (It also used the Fieldata character set - 6-bits, so 6 to the word). Anything using 8, 16, or 32 bit "words" is going to prefer Hex rather than octal, because octal digits do not fit neatly into the power-of-2 word sizes. Indeed, when Univac included the ASCII charater set, it used 9 bits rather than 8, so that each character fitted into a quarter word. So ... if you have an 8-bit microprocessor, Hex makes more sense than octal, because octal is always going to have a "short digit" at the front.
 
Top