1

Recently, I read some hex data with 16 length, like 0x1000 0000 0000 0000, but print out some strange thing when print 0xffff ffff ffff ffff

awk '{printf("0x\n", 0x1000000000000000)}'  output `0x1000000000000000`  ok.

But, instead with

16 f awk '{printf("0x\n", 0xffffffffffffffff)}', output 0

15 f awk '{printf("0x\n", 0xfffffffffffffff)}', output 1000000000000000 (14 0)

15 f awk '{printf("0x\n", 0xfffffffffffffff0)}', output 0

14 f awk '{printf("0x\n", 0xffffffffffffff)}', output 100000000000000 (13 0)

14 f awk '{printf("0x\n", 0xffffffffffffff0)}', output 100000000000000 (14 0)

14 f awk '{printf("0x\n", 0xffffffffffffff00)}', output 0

13 f awk '{printf("0x\n", 0xfffffffffffff)}', output fffffffffffff (13f)

13 f awk '{printf("0x\n", 0xfffffffffffff0)}', output fffffffffffff0 (13f)

13 f awk '{printf("0x\n", 0xfffffffffffff00)}', output fffffffffffff00 (13f)

13 f awk '{printf("0x\n", 0xfffffffffffff000)}', output fffffffffffff000 (13f)

so 13f is ok, how to print 16f?

Peng Liang
  • 115
  • 2
  • 6
  • 1
    possible duplicate of [Printing long integers in awk](http://stackoverflow.com/questions/8857866/printing-long-integers-in-awk) – tripleee Aug 08 '12 at 08:14
  • This prints a lot of `0x`, so I suppose the format string just left off. – TrueY Apr 21 '13 at 16:19

1 Answers1

1

You are missing the format string in the printf() call. Note that printfworks differently than print. I assume you see some random erratic behavior of the awk interpreter.

Another typical awk problem is that it typically uses double precision floating point numbers to represent all numeric value (also integers) so you would loose precision and get strange artifacts when you get near 64 bit. This depends on the actual awk implementation.

You are probably seeing a mixture of these two problems. I admit the rounding to 0 is bizarre.

Johannes Overmann
  • 4,914
  • 22
  • 38