in reply to How do I convert from decimal to hexidecimal?

Use the X, x and # format codes in printf and sprintf:
    $num = 15;

    printf("%X\n",     $num);   # F
    printf("%x\n",     $num);   # f
    printf("%02x\n",   $num);   # 0f
    printf("%#x\n",    $num);   # 0xf
    printf("0x%02x\n", $num);   # 0x0f
The last example is excessive but it forces formatting for zero:
    printf("%#x\n",    0);      # 0
    printf("0x%02x\n", 0);      # 0x00

  • Comment on Re: How do I convert from decimal to hexidecimal?