From 16baaa32f16dc65c2a7470c02fac31ae2d9158ef Mon Sep 17 00:00:00 2001 From: John Date: Tue, 9 Jul 2024 06:16:25 -0500 Subject: [PATCH] sample-code: Add an example function to print a number in hexadecimal --- sample-code/hex.cl | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 sample-code/hex.cl diff --git a/sample-code/hex.cl b/sample-code/hex.cl new file mode 100644 index 0000000..3e00d2e --- /dev/null +++ b/sample-code/hex.cl @@ -0,0 +1,12 @@ +pub fn hex(mut n: u64) { + let hex_lut = [ + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', + ]; + for xd in 0..16 { + let n = n >> (15 - xd) * 4; + if n != 0 { + print(hex_lut[n & 0xf]) + } + } + println() +}