-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
142 lines (102 loc) · 4.64 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
================================================================================
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 (gcc.gnu.org) 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
privileges.
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]
Options:
-h or --help
Print the help text
--version
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.
----------------------------------------
Author:
James Hendrie
hendrie.james@gmail.com
hendrie.james@protonmail.com
Sites:
http://www.someplacedumb/net/content/progs
https://github.com/jahendrie
https://github.com/jahendrie/dec2bin <-- This program!