printf( "%#04x", 1 )

Bob Jervis uunet!Eng.Sun.COM!Robert.Jervis
Thu Feb 24 18:09:56 PST 1994


The definition of printf describes the field width in terms of the number of
characters in the converted value.  The 0 flag says that zero padding is used
to expand the converted value to the desired field width.  Since the # flag is
decribed as specifying a conversion to an 'alternate form', I read the 0x prefix
as being part of the converted value.

So, 

	%#04x	of 1	->  0x01

By the way, the following is different:

	%#.4x	of 1	->  0x0001

because precision describes itself in terms of the number of significant digits
which would logically exclude the prefix.

Bob J

> From tydemanaibmpa.awdpa.ibm.com Fri Feb 25 08:54 PST 1994
> To: SC22WG14adkuug.dk
> Subject: printf( "%#04x", 1 )
> Cc: ncegacray.com
> 
> Subject: printf( "%#04x", 1 );
>  
> What string should be output by the above:
> 1) 0x01
> 2) 0x0001
> 3) Something else
>  
> In other words, is the '0x' counted in the field width?  If it is, then
> the output is 0x01.  If it is not, then the output is 0x0001.  Current
> vendors do it both ways.
>  
> These are not IBM's views, these are the personal ones of:
> Fred Tydeman, IBM, Austin, Texas (512) 838-3322; fax (512) 838-3484
> AIX S/6000 Math library architect & IBM's rep to NCEG (X3J11.1)
> Internet: tydemanaibmpa.awdpa.ibm.com    uucp: uunet!ibmsupt!tydeman
> 



More information about the Numeric-interest mailing list