Converting Decimal To Hex Or Octal
It turns out a number of people (at least two) wanted a simple program
to generate hex or octal numbers from immediate command-line input.
I'm a complete neophyte, but I figured I could probably manage that
little trick, so these are what I came up with.
You can download the source here.
Instructions are in the readme file, and couldn't be much clearer, but
this is the idea:
Either program will accept any number of decimal integers as input,
(all on one line)
and output either hexadecimal or octal numbers, one per line.
Integers only, at this point! If someone can give me a real good
argument for why floating point would be useful, I might get
interested in the problem.
For example:
hex 16 32 48
outputs:
0x10
0x20
0x30
oct works basically the same.
The program can also be called as dec, which will convert from either hex
or octal back to decimal. To get a hex-to-dec result, use either:
dec [number] (or)
dec 0x[number]
...either should give a good result. To get octal-to-dec conversion, use:
dec 0[number]
Please note that you can enter any number of hex _or_ octal numbers on any
line, but they must all be either one or the other. The first number sets
the pattern, so (for example):
dec 0x[number] [number] 0[number]
...will give you three conversions from hex to dec, even though the
third number requests octal-to-dec conversion.
--dave
d@timocharis.com