These programs convert between textual and binary representations of numbers. ascii2binary reads input consisting of textual representations of numbers separated by whitespace and produces as output the binary equivalents. The type and precision of the binary output is selected using command line flags.
binary2ascii reads input consisting of binary numbers and converts them to their textual representation. Command line flags specify the type and size of the binary numbers and provide control over the format of the output. Unsigned integers may be written out in binary, octal, decimal, or hexadecimal. Signed integers may be written out only in binary or decimal. Floating point numbers may be written out only decimal, either in standard or scientific notation. (If you want to examine the binary representation of floating point numbers, just treat the input as a sequence of unsigned characters.)
The two programs are useful for generating test data, for inspecting binary files, and for interfacing programs that generate textual output to programs that require binary input and conversely. They can also be useful when it is desired to reformat numbers. For example, the following pipeline was used to convert the variable length hex values of the endpoints of Unicode ranges to a uniform 6-digit length suitable for inclusion in a table:
awk '{print $1}' < UnicodeRanges | ascii2binary -b 16 -t ul | binary2ascii -b 16 -t ul -w 6 -x -z
and this pipeline will convert numbers from German format to American English format:
ascii2binary -t f -L de_DE < DeutscheZahlen | binary2ascii -L en_US -t f > AmericanNumbers
Language | C |
Environment | POSIX |
Dependencies | GNU gettext |
Current version | 2.14 |
Last modified | 2010-08-29 |
License | GNU General Public License |
The two programs are written in standard C and do not make use of any exotic libraries or system resources. They should compile and run on any POSIX-compliant system.
If you would like to be notified of new releases, subscribe to ascii2binary at Freshmeat.
cat intex.asc 0x10001000 ascii2binary -t ul < intex.asc > intex.bin binary2ascii -t ul < intex.bin 000268439552 binary2ascii -t ul -b h < intex.bin 0x10001000 binary2ascii -t ul -b b < intex.bin 00010000000000000001000000000000 binary2ascii -t uc -b b -n 4 < intex.bin 00000000 00010000 00000000 00010000 cat floatex.asc 2235.643 ascii2binary -t f < floatex.asc > floatex.bin binary2ascii -V -t f < floatex.bin 2235.643 binary2ascii -t f -p 1 -w 6 < floatex.bin 0002235.6 binary2ascii -t f -e < floatex.bin 2.236e+03 binary2ascii -t uc -b 2 < floatex.bin 01001010 10111010 00001011 01000101 binary2ascii -t uc -b 2 -n 4 < floatex.bin 01001010 10111010 00001011 01000101 binary2ascii -t uc -b 16 -n 4 < floatex.bin 0x4A 0xBA 0x0B 0x45 cat bfex.asc 10000000000000000000000000000000 ascii2binary -t f -b 2 < bfex.asc > bfex.bin binary2ascii -t f < bfex.bin 9999999848243207295109594873856.000 binary2ascii -t f -e < bfex.bin 1.000e+31 binary2ascii -t f -e -p 10 < bfex.bin 9.9999998482e+30
Both programs are fully internationalized. This means not only that the interface is available in more than one language, but that they can be used to generate numbers in the format appropriate for other countries and to convert between formats. A .po file is included with the source files for the use of anyone wishing to add a translation. A French translation is provided with the distribution. You may find these notes on Numbers and Locales helpful.
No bugs are known.