Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

11. Printing Text with the format Functi... > Control Sequences for Formatting Num...

Control Sequences for Formatting Numbers

The format command has many options designed specifically for controlling the appearance of numbers. Let’s look at some of the more useful ones.

Control Sequences for Formatting Integers

First, we can use format to display a number using a different base. For instance, we can display a number in hexadecimal (base-16) with the ˜x control sequence:

> (format t "The number 1000 in hexadecimal is ˜x" 1000)
The number 1000 in hexadecimal is 3E8

Similarly, we can display a number in binary (base-2) using the ˜b control sequence:

> (format t "The number 1000 in binary is ˜b" 1000)
The number 1000 in binary is 1111101000

We can even explicitly declare that a value will be displayed as a decimal (base-10) number, using the ˜d control sequence:


  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint