printf a uint64_t strips leading zeros

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

printf a uint64_t strips leading zeros

Ken Goldman
Windows XP with mingw:

I'd like to printf a uint64_t as a 16 hex character value.

The closest I found is %0I64x.  This strips leading 0's.  Is there a
different specifier that will keep leading zeros?


------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: printf a uint64_t strips leading zeros

Kai Tietz-2
2013/1/9 Ken Goldman <[hidden email]>:
> Windows XP with mingw:
>
> I'd like to printf a uint64_t as a 16 hex character value.
>
> The closest I found is %0I64x.  This strips leading 0's.  Is there a
> different specifier that will keep leading zeros?

Well, you were already pretty close, but not close enough ;) Use
%016I64x for pretting 64-bit value with all leading 0's.

Kai

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: printf a uint64_t strips leading zeros

lrn-2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09.01.2013 22:55, Kai Tietz wrote:

> 2013/1/9 Ken Goldman <[hidden email]>:
>> Windows XP with mingw:
>>
>> I'd like to printf a uint64_t as a 16 hex character value.
>>
>> The closest I found is %0I64x.  This strips leading 0's.  Is
>> there a different specifier that will keep leading zeros?
>
> Well, you were already pretty close, but not close enough ;) Use
> %016I64x for pretting 64-bit value with all leading 0's.
Also give %016llx a try.

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (MingW32)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQEcBAEBAgAGBQJQ7cL9AAoJEOs4Jb6SI2CwOagH/RqlPrIuW6560GpF1XaJOSIT
plT/1ELOVHK9p7OpODegx7P8wjaF4pbJvlOA8z09JxQfrz7zhg1GfiBoaQhyP8X7
vAG/wk8ne2Xf2v/6fbAt1JVFunrZHRUe3L7PDlqUCMch7IBdIlUXT5ZIKksd602Y
MYcs/4SDZrl5h+3lM0eztvTbMMPQ0OUJIDlFW4NeF/ob+HBz5IRYlz4gWp8dzYFx
CI7nxB4M+qhnw3FXUxV6G4b+/ElVJ4dzkpLE0xWAPs1i1/tiNlZmhZJVx198iGrb
hKbRLQqdxekDeb76WTbNKofXKrRFltlIOT3RYjGzor7kn3E+pUriyO+D0xamZk0=
=Pe2i
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: printf a uint64_t strips leading zeros

Gisle Vanem-2
"LRN" <[hidden email]> wrote:

>> Well, you were already pretty close, but not close enough ;) Use
>> %016I64x for pretting 64-bit value with all leading 0's.
> Also give %016llx a try.

The x64 version of gcc 4.7.2 (rubenvb-4.7.2-release) warns regarding
this:
  testc.c:180:3: warning: unknown conversion type character 'l' in format [-Wformat]

> gcc -v
Using built-in specs.
COLLECT_GCC=gcc
Target: x86_64-w64-mingw32
Configured with: /home/ruben/mingw-w64/src/gcc/configure --host=i686-w64-mingw32
--build=x86_64-linux-gnu
...

--gv


------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe
Reply | Threaded
Open this post in threaded view
|

Re: printf a uint64_t strips leading zeros

Keith Marshall
On 09/01/13 21:13, Gisle Vanem wrote:
> "LRN" <[hidden email]> wrote:
>>> Well, you were already pretty close, but not close enough ;) Use
>>> %016I64x for pretting 64-bit value with all leading 0's.
>>
>> Also give %016llx a try.
>
> The x64 version of gcc 4.7.2 (rubenvb-4.7.2-release) warns regarding
> this:
>    testc.c:180:3: warning: unknown conversion type character 'l' in format [-Wformat]

This is a deficiency in the -Wformat feature of GCC -- on WIN32
platforms, it erroneously assumes that only Microsoft's non-standard
formatting is valid, failing to recognise that MinGW provides an ISO
compatible alternative printf(3) implementation.  If you use this
alternative implementation, -Wformat is just plain broken!

--
Regards,
Keith.

------------------------------------------------------------------------------
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 
_______________________________________________
MinGW-users mailing list
[hidden email]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:[hidden email]?subject=unsubscribe