O'Reilly logo

Korn Shell: Unix and Linux Programming Manual, Third Edition, The by Anatole Olczak

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Arithmetic Constants

The format for arithmetic constants is:

number orbase#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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required