Skip to content
arxennPublic

About

Simple, dependency-free command-line converter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

hexc

A small, dependency-free command-line converter between text, hex, binary, decimal, octal and base64. Written in Go (stdlib only).

Installation

go install github.com/arxenn/hexc@latest

Build from source

go build -o hexc .          # or:  go install .
sudo mv hexc /usr/local/bin/

Usage

hexc [options] <from> <to> [input...]
hexc [options] all <from> [input...]
hexc                                    # interactive mode

Input comes from the arguments, or from stdin when none are given.

Format Aliases Example
text ascii, txt, str Hello (UTF-8, so Persian works)
hex h, 16 48 65 6c, 0x48 0x65, 48656c, \x48\x65
bin b, 2 01001000 01100101, 0b1001000
dec d, 10 72 101 108
oct o, 8 110 145 154
base64 b64 SGVsbG8=

Two modes

  • Number mode – between hex/bin/dec/oct, values are converted as (arbitrary-size) numbers: hexc hex dec ff -> 255.
  • Byte mode – whenever text or base64 is involved, values are raw bytes: hexc text hex Hello -> 48 65 6c 6c 6f. Force it between numeric formats with -b: hexc -b hex dec "01 f4" -> 1 244.

Options (before <from>)

-u, --upper     uppercase hex digits
-p, --prefix    add 0x / 0b / 0o prefixes
-s, --sep STR   output separator (default " "; -s "" for none)
-b, --bytes     force byte mode for numeric formats

Examples

hexc text hex "Hello, World"       # 48 65 6c 6c 6f 2c 20 57 6f 72 6c 64
hexc hex text 48656c6c6f           # Hello
hexc hex bin ff                    # 11111111
hexc dec hex 255 4096              # ff 1000
hexc -u -p dec hex 48879           # 0xBEEF
hexc -s "" text hex hi             # 6869
hexc text b64 Salam                # U2FsYW0=
hexc all text "hi"               # every representation at once
echo -n secret | hexc text hex     # 73 65 63 72 65 74

Interactive mode

Run hexc with no arguments, type values, and switch formats with : commands:

[text -> hex] > Hello
48 65 6c 6c 6f
[text -> hex] > :hex bin
[hex -> bin] > ff
11111111
[hex -> bin] > :all
[hex -> all] > 255

:help lists everything (:swap, :upper, :prefix, :bytes, :sep, :status, :quit). Wrap it in rlwrap hexc if you want arrow-key history.

Test

go test ./...

About

Simple, dependency-free command-line converter

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages