A lightweight calculator for your CLI.
Supports binary, hex and decimal inputs and outputs.
xc [-dhb] [expression]
-d
-h
-b
control the output format (dec, hex and/or bin) - if none are specified, all are outputted in a pretty formatexpression
is an expression to be calculated, if one isn't given thenxc
opens in interactive mode
100 => 100 (dec)
0x100 => 256 (hex)
100h => 256 (hex)
A0 => 160 (hex)
0b100 => 4 (bin)
100b => 4 (bin)
Add => "+"
Mul => "*"
Lparen => "("
Rparen => ")"
Sub => "-"
Div => "/"
Remainder => "%"
Pow => "**"
Neg => "-"
BNot => "~"
BXor => "^"
BOr => "|"
BAnd => "&"
LShift => "<<"
RShift => ">>"
Assign => "="
Variables must begin with a $
character and their names consist of alphanumeric characters and the _
character.
$ xc '$x = 1+1; $y = $x * 2; $y << 3;'
> $x = 1+1
> $y = $x * 2
> $y << 3
Dec 32
Hex 20 h
Bin 10 0000 b
--4----0
Functions can be declared with the format |arg1, arg2, ...| expr
. They can then be called with $func_name(arg1, arg2, ...)
.
$ xc '$x = |$i| $i*2; $y = |$f, $i| $f($i) + 3; $y($x, 1)'
> $x = |$i| $i*2
> $y = |$f, $i| $f($i) + 3
> $y($x, 1)
Dec 5
Hex 5 h
Bin 101 b
---0
- interactive mode
- show different formats for output
- multiple expressions in one invocation of
xc
- store calculation results in variables for reusing in future expressions
- functions
- read / write values from and to a file given a filename, offset and number of bytes