# bb

bb is a hex calculator for the console. bb makes working with hexadecimal numbers as painless as possible.

See the files README and FEATURES for details.

Some features of bb:

• hex-friendly syntax
• arbitrary precission arithmetic
• complex expression evaluation
• support for both unlimited integers and integers with a specified width
• arithmetic, shift, and logical operators
• bit selection operators
• input of hexadecimal, decimal, octal, and binary numbers
• name binding (ie. "storing" values with a name)
• written in Haskell, thus very portable
• works with Hugs (no compilation necessary) and GHC

## Operators

Here is the current list of operators to give you an impression what bb can do:

```
Operators
---------

-           subtraction
*           multiplication
/           integer division
%           remainder
//          floor of real division
%%          modulo (zero or same sign as divisor)

&           bitwise AND
|           bitwise OR
^           bitwise XOR

unary -     negation
unary ~     complement

<<          shift left
>>          shift right
s>>         signed shift right
<<<         rotate left
>>>         rotate right

u*u         multiplication with zero/zero extension
s*u         multiplication with sign/zero extension
u*s         multiplication with zero/sign extension
s*s         multiplication with sign/sign extension

u/u         unsigned division
s/u         signed/unsigned division
u/s         unsigned/signed division
s/s         signed/signed division

:hi#        select high # bits
:lo#        select low # bits
:msb        select MSB
:lsb        select LSB
:#          select bit #
:#-#        select bit range (can use 'msb' and 'lsb' in place of #)
:(...)      select bit list, eg. :(0,5-msb)

[...]#      put in a box of # bits width
unary ^     unbox
unary ^s    unbox signed

<-          name binding

NOTE: The # in this list are decimal numbers that are regarded as
quoted by bb -- and therefore always interpreted as decimal.
You cannot put expressions there.

NOTE: Many operators only exhibit their special behaviour when
working on boxes (ie. values of fixed width).

NOTE: The division and remainder/modulo operators satisfy the
following equations:

(a /  b) * b + (a %  b) == a
(a // b) * b + (a %% b) == a

```