Re: understanding format specifiers



siliconwafer wrote:

What does a 'format specifier' do?
Suppose I do,
int a = 43;  //decimal number

Only the representation of the number in the source code is decimal. Inside the memory the number is stored in binary.

The line
int a = 0x2b;
will store the same binary number in memory.
It is not stored in hexadecimal format.


printf("%x",a);
I will get hex equivalent of 43.
Does the format specifier do an implicit "decimal to hex" conversion
before displaying ?

No, in the above example printf gives you a hexadecimal representation of the value of variable a.

printf("%d\n", a);
prints a decimal representation of variable a.
In both cases printf has to do a "conversion".
It has to work with the value of a to get a certain
representation of this value. The format specifier
tells printf which representation you want.

regards
Ralf
.



Relevant Pages

  • Re: Get memory representation of double
    ... I want to get the representation in memory of a variable of type ... int is 16-bits). ... the double precision representation of 1/3 is 3fd5 5555 ... to an array of unsigned short int but does not seem to work. ...
    (comp.lang.c)
  • REPOST: Re: observation on NAF
    ... >>binary representation by doing a digitwise subtraction of n from 2n ... int mods{ ... I bet you can build a faster wNAF generator. ... I think the main benefit of the wNAF is its memory efficiency. ...
    (sci.crypt)
  • Re: observation on NAF
    ... >>binary representation by doing a digitwise subtraction of n from 2n ... int mods{ ... I bet you can build a faster wNAF generator. ... I think the main benefit of the wNAF is its memory efficiency. ...
    (sci.crypt)
  • [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver.
    ... * Binds a collection of pages into AGP memory at the given offset, ... new file mode 100644 ... * The above copyright notice and this permission notice (including the ... +static int ...
    (Linux-Kernel)
  • [PATCH] drm: Add GEM ("graphics execution manager") to i915 driver.
    ... * Binds a collection of pages into AGP memory at the given offset, ... new file mode 100644 ... * The above copyright notice and this permission notice (including the ... +static int ...
    (Linux-Kernel)