Skip to Content
Land of Lisp
book

Land of Lisp

by Conrad Barski M.D.
November 2010
Intermediate to advanced
504 pages
12h 45m
English
No Starch Press
Content preview from Land of Lisp

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Practical Common Lisp

Practical Common Lisp

Peter Seibel
The Rust Programming Language, 2nd Edition

The Rust Programming Language, 2nd Edition

Steve Klabnik, Carol Nichols
Programming Rust, 2nd Edition

Programming Rust, 2nd Edition

Jim Blandy, Jason Orendorff, Leonora F. S. Tindall
The Go Programming Language

The Go Programming Language

Alan A. A. Donovan, Brian W. Kernighan

Publisher Resources

ISBN: 9781593272814Errata Page