Is there a formula that converts a number from 0 to 959 to a corresponding chess960 position? I am looking into a website with starting positions for chess960.

000 BBQNNRKR
001 BQNBNRKR
002 BQNNRBKR
003 BQNNRKRB
004 QBBNNRKR
005 QNBBNRKR
...
959 RKRNNQBB


So there is a table that converts any number from 0 to 959 to a starting position. For example chess960(518) = 'RNBQKBNR' normal starting chess position.

What is this formula? How can I do this without storing all the table?
From Wikipedia:


  White's Chess960 starting array can be derived from its number N (0
  ... 959) as follows:
  
  a) Divide N by 4, yielding quotient N2 and remainder B1. Place a
  Bishop upon the bright square corresponding to B1 (0=b, 1=d, 2=f,
  3=h).
  
  b) Divide N2 by 4 again, yielding quotient N3 and remainder B2. Place
  a second Bishop upon the dark square corresponding to B2 (0=a, 1=c,
  2=e, 3=g).
  
  c) Divide N3 by 6, yielding quotient N4 and remainder Q. Place the
  Queen according to Q, where 0 is the first free square starting from
  a, 1 is the second, etc.
  
  d) N4 will be a single digit, 0 ... 9. Place the Knights according to
  its value by consulting the following table:

0     N   N   -   -   -
1     N   -   N   -   -
2     N   -   -   N   -
3     N   -   -   -   N
4     -   N   N   -   -
5     -   N   -   N   -
6     -   N   -   -   N
7     -   -   N   N   -
8     -   -   N   -   N
9     -   -   -   N   N

  
  e) There are three blank squares remaining; place a Rook in each of
  the outer two and the King in the middle one.