hex package:sbv

Show a number in hex, without prefix, or types.
Show a number in hexadecimal, starting with 0x but no type.
Show a number in hexadecimal, starting with 0x and type.
Recognize a hexadecimal digit. One of 0..9, a..f, A..F.
>>> hexDigit
(re.union (re.range "0" "9") (re.range "a" "f") (re.range "A" "F"))

>>> prove $ \c -> c `match` hexDigit .<=> let v = digitToInt c in 0 .<= v .&& v .< 16
Q.E.D.

>>> prove $ \(c :: SChar) -> c `match` digit .=> c `match` hexDigit
Q.E.D.
Recognize a hexadecimal number. Must have a prefix of the form 0x/0X.
>>> hexadecimal
(re.++ (re.union (str.to.re "0x") (str.to.re "0X")) (re.+ (re.union (re.range "0" "9") (re.range "a" "f") (re.range "A" "F"))))

>>> prove $ \(s :: SString) -> s `match` hexadecimal .=> sAny (.== take 2 s) ["0x", "0X"]
Q.E.D.
For doctest purposes only
For doctest purposes only
We're given a board, with 19 hexagon cells. The cells are arranged as follows:
01  02  03
04  05  06  07
08  09  10  11  12
13  14  15  16
17  18  19
  • Each cell has a color, one of BLACK, BLUE, GREEN, or RED.
  • At each step, you get to press one of the center buttons. That is, one of 5, 6, 9, 10, 11, 14, or 15.
  • Pressing a button that is currently colored BLACK has no effect.
  • Otherwise (i.e., if the pressed button is not BLACK), then colors rotate clockwise around that button. For instance if you press 15 when it is not colored BLACK, then 11 moves to 16, 16 moves to 19, 19 moves to 18, 18 moves to 14, 14 moves to 10, and 10 moves to 11.
  • Note that by "move," we mean the colors move: We still refer to the buttons with the same number after a move.
You are given an initial board coloring, and a final one. Your goal is to find a minimal sequence of button presses that will turn the original board to the final one.
Is this a Hex digit, i.e, one of 0..9, a..f, A..F.
>>> prove $ \c -> isHexDigit c .=> isAlphaNumL1 c
Q.E.D.
If True, then 8-bit unsigned values will be shown in hex as well, otherwise decimal. (Other types always shown in hex.)
If passed True, then we will show 'SWord 8' type in hex. Otherwise we'll show it in decimal. All signed types are shown decimal, and all unsigned larger types are shown hexadecimal otherwise.
Show as hexadecimal, but for C programs. We have to be careful about printing min-bounds, since C does some funky casting, possibly losing the sign bit. In those cases, we use the defined constants in stdint.h. We also properly append the necessary suffixes as needed.
Show as a hexadecimal value. First bool controls whether type info is printed while the second boolean controls whether 0x prefix is printed. The tuple is the signedness and the bit-length of the input. The length of the string will not depend on the value, but rather the bit-length.
Show as a hexadecimal value, integer version. Almost the same as shex above except we don't have a bit-length so the length of the string will depend on the actual value.