简体   繁体   中英

Perl: Decimal to 32bits hex convert

I want to convert decimal number 64 into hex representation: 0x00000040 . I am using

printf("0x%X", 64);

but it gives output: 0x40 . Can anyone please help me how to represent the decimal number in 0x00000000 format?

You can specify the length of the field between the % and the X (eg %8X ). By default, the number will be padded with spaces, but using a leading zero for the length (eg %08X ) will cause printf to pad with zeroes instead. Therefore, the following can be used:

printf("0x%08X", 64);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM