on master help sign in
Add bitsToHexStr to Data.Bits

Add a helper for printing the hex value of wrapped `Bits`, as it's usually more convenient than the binary. Changing the `Show` instance here would be breaking, I guess.

commit988f5b9c8077c6af505992d6e72ebb6d694258e3 authorAlex Gryzlov <skyrodent@gmail.com> dateWed 31 Jan 2018, 19:16 (9 years ago) parent80932ef
1 file changed+8
libs/base/Data/Bits.idr+8
libs/base/Data/Bits.idr+8
@@ -501,5 +501,13 @@ bitsToStr x = pack (helper last x)
501501 helper FZ _ = []
502502 helper (FS x) b = assert_total $ (if getBit x b then '1' else '0') :: helper (weaken x) b
503503
504+bitsToHexStr : %static {n : Nat} -> Bits n -> String
505+bitsToHexStr {n} (MkBits b) with (nextBytes n)
506+ | Z = b8ToHexString b
507+ | S Z = b16ToHexString b
508+ | S (S Z) = b32ToHexString b
509+ | S (S (S Z)) = b64ToHexString b
510+ | _ = assert_unreachable
511+
504512implementation Show (Bits n) where
505513 show = bitsToStr