bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

printf "%c" and numbers above 255


From: Hermann Peifer
Subject: printf "%c" and numbers above 255
Date: Sat, 10 May 2008 00:30:44 +0200
User-agent: Thunderbird 2.0.0.12 (X11/20080227)

According to the printf documentation in the Gawk manual:

|%c |This prints a number as an ASCII character; thus, `printf "%c", 65' outputs the letter `A'.

My observations is that this works fine for numbers 0..127 and even for 128..255 (although resulting characters of the latter range are perhaps not ASCII characters).

For numbers above 255, printf basically prints the character of number%256, e.g.:

$ awk 'BEGIN{printf "%c\n",65+256}'
A
$ awk 'BEGIN{printf "%c\n",65+256+256}'
A


I'm not quite sure if this is a bug or feature. For me it was at least somewhat surprising.

Hermann

PS
A nice enhancement would be if printf could print Unicode characters, similar to /usr/bin/printf, which has the formats \uHHHH and \UHHHHHHHH:

\uHHHH   Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)
\UHHHHHHHH  Unicode character with hex value HHHHHHHH (8 digits)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]