Ascii2Binary/Binary2Ascii

Convert Between Textual Representations of Numbers and Binary

Contents

  1. Description
  2. Details
  3. Environment
  4. Downloads
  5. Examples
  6. Documentation
  7. Change Log
  8. Localization
  9. Bugs

Description

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

Back to Top

Details

LanguageC
EnvironmentPOSIX
DependenciesGNU gettext
Current version2.14
Last modified2010-08-29
LicenseGNU General Public License

Environment

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.


Back to Top

Downloads (source files and man pages)


ascii2binary-2.14.tar.gz
ascii2binary-2.14.tar.bz2
ascii2binary-2.14.zip

If you would like to be notified of new releases, subscribe to ascii2binary at Freshmeat.


Debian

FreeBSD Freshport

Open Package

Open Solaris

Suse Linux RPMs

Ubuntu

Back to Top

Examples

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


Back to Top

Documentation

ascii2binary

binary2ascii


Change Log

Version 2.14

Version 2.13

Version 2.12


Full Change Log
Back to Top

Localization

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.


Back to Top

Bugs

No bugs are known.



Back to Top

Back to Bill Poser's software page.