Converting base 8

Consider the following function that converts a positive decimal number to base 8 and displays the result.


I dont know how to trace the function
Last edited on
To "trace" they mean show what the value of n is at each step.

So, for displayOctal( 8 ) I would say:

  displayOctal( 8 ):
    n = 8
    if (n > 0) --> if (8 > 0)
      displayOctal( 8/8 --> 1 )
        n = 1
        if (n > 0) --> if (1 > 0)
          displayOctal( 1/8 --> 0 )
            n = 0
            if (n > 0) --> if (0 > 0)
              done
          print n%8 --> print 1%8 --> print 1
      print n%8 --> print 8%8 --> print 0

So the ordered output is "10".

Hope this helps.
Topic archived. No new replies allowed.