sample-code: Add an example function to print a number in hexadecimal

This commit is contained in:
John 2024-07-09 06:16:25 -05:00
parent 3c4d31c473
commit 16baaa32f1

12
sample-code/hex.cl Normal file
View File

@ -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()
}