| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Bytes: showing bit patterns |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
{-# OPTIONS --cubical-compatible #-} |
| 8 |
|
| 9 |
module Data.Word8.Show where |
| 10 |
|
| 11 |
open import Agda.Builtin.String using (String) |
| 12 |
|
| 13 |
open import Data.Bool.Show using (showBit) |
| 14 |
open import Data.Fin.Base as Fin using (Fin) |
| 15 |
import Data.Nat.Show as ℕ using (showInBase) |
| 16 |
open import Data.String using (_++_; fromVec; padLeft) |
| 17 |
open import Data.Vec.Base as Vec using (Vec; []; _∷_) |
| 18 |
open import Data.Word8.Base using (Word8; toℕ; toBits) |
| 19 |
open import Function.Base using (_$_) |
| 20 |
|
| 21 |
showBits : Word8 → String |
| 22 |
showBits w |
| 23 |
= "0b" ++_ |
| 24 |
$ fromVec |
| 25 |
$ Vec.reverse |
| 26 |
$ Vec.map showBit |
| 27 |
$ toBits w |
| 28 |
|
| 29 |
showHexa : Word8 → String |
| 30 |
showHexa w |
| 31 |
= "0x" ++_ |
| 32 |
$ padLeft '0' 2 |
| 33 |
$ ℕ.showInBase 16 (toℕ w) |