[ale] $PS1 stuff

Michael Hirsch hirsch at mathcs.emory.edu
Mon Apr 12 13:03:05 EDT 1999


David S. Jackson writes:

> second:  I'd like to add nifty ASCII characters to the PS1 line, but I have
> to enter their octal values as \nnn where "nnn" = the octal value of the
> ASCII character in question.  I found an old table with decimal and hex
> equivalents, but how do I convert them to octal for the PS1 variable?

Here's an easy algorithm.  Suppose you are trying to convert n into
base eight.

Divide n by 8 to get m with remainder r.  Then r is the lowest order
digit (the ones digit).

Now let n = m and repeat until there is nothing left.

For example: Lets convert 100 to base 8

100/8 = 12 with remainder 4
12/8 = 1 with remainder 4
1/8 = 0 with remainder 1

So 100 base 10 = 144 base 8

--Michael






More information about the Ale mailing list