Tired of printing octals and hexadecimals and then mentally converting them to bits. Ever wanted to just see the bits in an int? Now you can!
Just run opam install pp-binary-ints and off you go:
# Pp_binary_ints.Int.to_string 0b10101001;;
- : string = "10101001"
You can find the documentation for the project and more examples of how to use it here.
The library is very customizable.
- You can choose to print with
0bprefixes and_separators. - You can choose to print zeros just like the non-zeros, with prefixes and separators.
- If you use zero padding, you can control how many leading zeros show up with the
~min_widthargument. - It correctly handles the edge cases when adding
_separators: you won’t get leading underscores. - It includes pretty printers that work with
FormatandFmt, not justto_stringfunctions. - Supports
int,int32,int64, andnativeint. - Don’t like the default prefixes and suffixes? Customize the prefixes and suffixes with the provided functor.