sample-code: Add an example function to print a number in hexadecimal
This commit is contained in:
parent
3c4d31c473
commit
16baaa32f1
12
sample-code/hex.cl
Normal file
12
sample-code/hex.cl
Normal 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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user