1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<html lang="en">
<head>
<title>Integer Conversions - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" title="C-Style I/O Functions">
<link rel="prev" href="Table-of-Output-Conversions.html#Table-of-Output-Conversions" title="Table of Output Conversions">
<link rel="next" href="Floating_002dPoint-Conversions.html#Floating_002dPoint-Conversions" title="Floating-Point Conversions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Integer-Conversions"></a>
Next: <a rel="next" accesskey="n" href="Floating_002dPoint-Conversions.html#Floating_002dPoint-Conversions">Floating-Point Conversions</a>,
Previous: <a rel="previous" accesskey="p" href="Table-of-Output-Conversions.html#Table-of-Output-Conversions">Table of Output Conversions</a>,
Up: <a rel="up" accesskey="u" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions">C-Style I/O Functions</a>
<hr>
</div>
<h4 class="subsection">14.2.8 Integer Conversions</h4>
<p>This section describes the options for the ‘<samp><span class="samp">%d</span></samp>’, ‘<samp><span class="samp">%i</span></samp>’,
‘<samp><span class="samp">%o</span></samp>’, ‘<samp><span class="samp">%u</span></samp>’, ‘<samp><span class="samp">%x</span></samp>’, and ‘<samp><span class="samp">%X</span></samp>’ conversion
specifications. These conversions print integers in various formats.
<p>The ‘<samp><span class="samp">%d</span></samp>’ and ‘<samp><span class="samp">%i</span></samp>’ conversion specifications both print an
numeric argument as a signed decimal number; while ‘<samp><span class="samp">%o</span></samp>’,
‘<samp><span class="samp">%u</span></samp>’, and ‘<samp><span class="samp">%x</span></samp>’ print the argument as an unsigned octal,
decimal, or hexadecimal number (respectively). The ‘<samp><span class="samp">%X</span></samp>’ conversion
specification is just like ‘<samp><span class="samp">%x</span></samp>’ except that it uses the characters
‘<samp><span class="samp">ABCDEF</span></samp>’ as digits instead of ‘<samp><span class="samp">abcdef</span></samp>’.
<p>The following flags are meaningful:
<dl>
<dt>‘<samp><span class="samp">-</span></samp>’<dd>Left-justify the result in the field (instead of the normal
right-justification).
<br><dt>‘<samp><span class="samp">+</span></samp>’<dd>For the signed ‘<samp><span class="samp">%d</span></samp>’ and ‘<samp><span class="samp">%i</span></samp>’ conversions, print a
plus sign if the value is positive.
<br><dt>‘<samp> </samp>’<dd>For the signed ‘<samp><span class="samp">%d</span></samp>’ and ‘<samp><span class="samp">%i</span></samp>’ conversions, if the result
doesn't start with a plus or minus sign, prefix it with a space
character instead. Since the ‘<samp><span class="samp">+</span></samp>’ flag ensures that the result
includes a sign, this flag is ignored if you supply both of them.
<br><dt>‘<samp><span class="samp">#</span></samp>’<dd>For the ‘<samp><span class="samp">%o</span></samp>’ conversion, this forces the leading digit to be
‘<samp><span class="samp">0</span></samp>’, as if by increasing the precision. For ‘<samp><span class="samp">%x</span></samp>’ or
‘<samp><span class="samp">%X</span></samp>’, this prefixes a leading ‘<samp><span class="samp">0x</span></samp>’ or ‘<samp><span class="samp">0X</span></samp>’ (respectively)
to the result. This doesn't do anything useful for the ‘<samp><span class="samp">%d</span></samp>’,
‘<samp><span class="samp">%i</span></samp>’, or ‘<samp><span class="samp">%u</span></samp>’ conversions.
<br><dt>‘<samp><span class="samp">0</span></samp>’<dd>Pad the field with zeros instead of spaces. The zeros are placed after
any indication of sign or base. This flag is ignored if the ‘<samp><span class="samp">-</span></samp>’
flag is also specified, or if a precision is specified.
</dl>
<p>If a precision is supplied, it specifies the minimum number of digits to
appear; leading zeros are produced if necessary. If you don't specify a
precision, the number is printed with as many digits as it needs. If
you convert a value of zero with an explicit precision of zero, then no
characters at all are produced.
</body></html>
|