The format for arithmetic constants is:

`number` or`base#number`

where base is a whole number between 2 and 36, and number is any non-negative integer. If not specified, the default base is 10. The arithmetic base of a variable can be set with the typeset –in command, or by prepending base# to the value. In this example, variable X is set to 5 in base 2 using both formats:

```
$ typeset —i2 X=5
```

or

```
$ typeset —i X=2#101
```

When variable X is expanded, the value is written in base 2:

$ print $X 2#101

If you want to display the value of X in another base, just reset the base with the typeset –in command. Here it is reset to base 3:

$ typeset —i3 X $ print $X 3#12

Arithmetic can be performed on numbers with different bases. Here ...

Start Free Trial

No credit card required