Dots in hex printf

Hi. I was wondering why there are dots in printing out a hexadecimal
number:

1ecashin@meili linux-2.4.18-kgdb$ perl -e 'printf “%x\n”, ~(8192 - 1)'
ffffe000
ecashin@meili linux-2.4.18-kgdb$ ruby -e ‘printf “%x\n”, ~(8192 - 1)’
…fe000
ecashin@meili linux-2.4.18-kgdb$ ruby -e ‘printf “%x\n”, (~(8192 - 1))’
…fe000

… but it works with the literal number in there.

ecashin@meili linux-2.4.18-kgdb$ ruby -e 'printf “%x\n”, 0xffffe000’
ffffe000

···


–Ed L Cashin PGP public key: http://noserose.net/e/pgp/

Hi,

···

In message “dots in hex printf” on 03/04/21, Ed L Cashin ecashin@uga.edu writes:

Hi. I was wondering why there are dots in printing out a hexadecimal
number:

You were trying to print negative numbers in hexadecimal. Ruby
assumes virtual infinite on-bits leftward for negative numbers. Dots
represents omitted bits on left side. If you don’t want those dots,
specify format precision (e.g. “%.5x”), or bit-and with mask bits
(e.g. x & 0xffff).

						matz.

matz@ruby-lang.org (Yukihiro Matsumoto) writes:

Hi,

Hi. I was wondering why there are dots in printing out a hexadecimal
number:

You were trying to print negative numbers in hexadecimal. Ruby
assumes virtual infinite on-bits leftward for negative numbers. Dots
represents omitted bits on left side. If you don’t want those dots,
specify format precision (e.g. “%.5x”), or bit-and with mask bits
(e.g. x & 0xffff).

OK, thanks. I have always thought of printf as treating the argument
associated with %x as unsigned (in which case I suppose there wouldn’t
be an infinite sign extension), but I can adjust.

···

In message “dots in hex printf” > on 03/04/21, Ed L Cashin ecashin@uga.edu writes:


–Ed L Cashin PGP public key: http://noserose.net/e/pgp/