Skip to content
Switch branches/tags

Latest commit


Git stats


Failed to load latest commit information.
Latest commit message
Commit time
    dec2bin.c   |   Version 1.5     |   FreeBSD License     |   2017-11-20
    James Hendrie                   |   hendrie dot james at gmail dot com

    1.  Description
    2.  Installation / Uninstallation
    3.  Usage
    4.  Examples
    5.  Known limitations
    6.  Contact, etc.

    1.  Description

    dec2bin (working title) is a program that will convert decimal numbers to
    their binary equivalents.  It can also convert to hexadecimal or octal if
    you'd like it to do that.

    This is the companion to another program I've written recently, named
    bin2dec; that program converts binary numbers to decimal.

    2.  Installation / Uninstallation

    To install, compile the program with 'make'.  It shouldn't take long, though
    obviously you'll need a C compiler.  If you're on any modern UNIX or Linux
    distro you should already have one, and if you don't, shame on you.  Go
    install GCC ( right away.

    After you've compiled the program, install it to your system by issuing
    'make install' with superuser privileges.

    To remove the program and all its accessories, return to the directory to
    which you originally extracted the tarball (or whichever directory has the
    Makefile for this program) and type 'make uninstall', again with superuser

    Alternately, if you're on a Slackware system, you can install the Slackware
    package for this program using the in-built package manager.  You should be
    able to find it in the same place you found this tarball.

    3.  Usage

Usage:  dec2bin [OPTIONS] NUMBER[s]

    -h or --help
        Print the help text
        Print version and author info

    -v  Print the number type (DEC, HEX, OCT) before the number (verbosity)
    -b  Binary output (default)
    -d  Decimal output
    -o  Octal output
    -x  Hexadecimal output
    -X  Hex output with capital letters
    -a  Precise hexadecimal output (printf %a, see 'man 3 printf for more info)
    -A  Precise hexadecimal output with capital letters
    -s  Print output in 4-character sections, space-separated
    -l  Print a line between sections of output
    -t  Turn on textmode conversion (convert from ASCII to binary)
    -e  Specify little-endian printing
    -E  Specify big-endian printing (default)
    -   Read numbers from stdin

    4.  Examples

dec2bin 2
    This will print 10 to your terminal.

dec2bin 15
    This will print 1111 to your terminal.

dec2bin 15 16 728110
    This will print the numbers 1111, 10000 and 10110001110000101110 to your
    terminal, each on its own line.

dec2bin -oxb 15 16
    This will print the octal, binary and hexadecimal equivalents to 15 and 16
    to your terminal.

dec2bin -vXbsl 1029 18349
    This will print the binary and hexadecimal (with capital letters)
    equivalents to 1029 and 18349 to your terminal, separated into 4-character
    sections with each number's equivalents separated by a new line.  Each line
    of text will also, at the front of it, have its type of output specified (in
    this case, either HEX or BIN).

dec2bin -t "pizza"
    This will convert the ASCII text 'pizza' to a binary number:
    '0111000001101001011110100111101001100001'.  Combine with '-vl' options
    for more informative results.

echo 1029 18349 | dec2bin -vls -Xb -
    This will result in the same output as above, only in this instance the
    input has been read from stdin and, just for fun, I've arranged the
    arguments differently.

cat 'gilgamesh.txt' | dec2bin -t -
    Annoy your friends by sending them binary epics

    5.  Known limitations

    The program can't handle numbers greater than (1e16)-2 (9999999999999998).
    It also assumes unsigned integers -- i.e., won't work with negatives.

    6.  Contact, etc.

        James Hendrie

      <-- This program!


Convert decimal numbers to binary



No releases published


No packages published