# A pretty bit viewer

## Installation

```
cargo install bitsutils
```

## Usage

### Display bits of a single number

```
bits 1234
# in hex
bits 0x1234
bits 1234h
# in binary
bits 0b1010
bits 1010b
# in octal
bits 0o1234
bits 1234o
```

Example output:

```
1234 = 0x4d2 = 0b10011010010
 bit  v  desc
---------------
 0    0
 1    1
 2    0
 3    0
 4    1
 5    0
 6    1
 7    1
 8    0
 9    0
 10   1
 11   0
 12   0
 13   0
 14   0
 15   0
```

### Display bits of multiple numbers, show difference

```
bits 0x0f 0x1f
```

Example output:

```
15 = 0xf = 0b1111
 bit  v  desc
---------------
 0    1
 1    1
 2    1
 3    1
 4    0
 5    0
 6    0
 7    0

31 = 0x1f = 0b11111
 bit  v  desc
---------------
 0    1
 1    1
 2    1
 3    1
 4    1  >>
 5    0
 6    0
 7    0
```

### Add a bit map

Specify a bit map with `--bitmap` or `-m` option or in `BITMAP` environment
variable (YAML or JSON file).

Example bit map for EtherCAT control PDO:

```yaml
bits:
  0: switch on
  1: voltage
  2: quick stop
  3: operation
  4: new set point
  7: fault reset
  8: halt
```

Now the known bits are displayed with their description:

```
bits 0x0f 0x1f
```

Output:

```
15 = 0xf = 0b1111
 bit  v  desc
------------------------
 0    1  switch on
 1    1  voltage
 2    1  quick stop
 3    1  operation
 4    0  new set point
 5    0
 6    0
 7    0  fault reset

31 = 0x1f = 0b11111
 bit  v  desc
---------------------------
 0    1  switch on
 1    1  voltage
 2    1  quick stop
 3    1  operation
 4    1  >> new set point
 5    0
 6    0
 7    0  fault reset
```