Skip to content

Convert between all bases 2..256 the most efficient way possible

License

Notifications You must be signed in to change notification settings

andres-erbsen/baseconvert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

baseconvert - optimized universal base converter in ANSI C

Converts between bases 2..256. Each character in the input is one digit. Values of digits are specified in files specified using command line arguments, because 0 byte cannot be put into the argv.

Picks the optimal method

If some number of digits in one base directly corresponds to some other number of digits in the other base, baseconvert processes the input in groups of that many characters. For example, 1111 in base 2 means F in hex, no matter which group it is. List of such pairs is in shortcuts.txt.

Examples

Convert a simple number from decimal to hexademical:

$ echo -n 15 | ./baseconvert decimal.txt hex.txt && echo 
f

Get the raw bytes of a hash value:

$ sha512sum important.txt | cut -d ' ' -f1 | tr -d '\n' | ./baseconvert hex.txt bytes.txt > rawhash

Adding new bases

Bases are defined in text files of digits in their actual ordering. The first character means 0, the second means 1 and so on. All characters in the file are considered to be digits, so you probably want to remove the newline at the end. One easy way to do it is:

cat origbase.txt | tr -d '\n' > correctbase.txt

What baseconvert does not do

(The wheels not reinvented this time)

  • Add padding or newlines to output
  • Process padding or newlines in input
  • Read input from a file

About

Convert between all bases 2..256 the most efficient way possible

Resources

License

Stars

Watchers

Forks

Packages

No packages published