O'Reilly logo

Advanced Mac OS X Programming: The Big Nerd Ranch Guide by Mark Dalrymple

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

Displaying Data

print can be used to display variables and the result of function calls. You can control the format of the displayed data by adding a format flag after the command:

(​g​d​b​)​ ​p​r​i​n​t​ ​i​
$​1​ ​=​ ​1​7​2​6​3​8​1​2​

(​g​d​b​)​ ​p​r​i​n​t​/​x​ ​i​
$​2​ ​=​ ​0​x​1​0​7​6​c​c​4​

(​g​d​b​)​ ​p​r​i​n​t​ ​/​o​ ​i​
$​3​ ​=​ ​0​1​0​1​6​6​6​3​0​4​

(​g​d​b​)​ ​p​r​i​n​t​/​t​ ​i​
$​4​ ​=​ ​1​0​0​0​0​0​1​1​1​0​1​1​0​1​1​0​0​1​1​0​0​0​1​0​0​

Here are some of the format flags:

/x

Hexadecimal

/d

Signed decimal

/u

Unsigned decimal

/o

Octal

/t

Binary (t for "two")

/c

Print as a character constant

/f

Floating point

You can use these in ad-hoc expressions too:

(​g​d​b​)​ ​p​r​i​n​t​/​o​ ​0​x​f​e​e​d​f​a​c​e​ $​5​ ​=​ ​0​3​7​6​7​3​3​7​5​3​1​6​ ...

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