sample-code/ascii: Use as
casting to print the entire printable ASCII range
This commit is contained in:
parent
38a5d31b08
commit
3aef055739
28
sample-code/ascii.cl
Normal file
28
sample-code/ascii.cl
Normal file
@ -0,0 +1,28 @@
|
||||
//! Prints out the characters in the ASCII printable range
|
||||
//! in the format of a hex-dump
|
||||
|
||||
// TODO: Convenient stuff like this in the stdlib
|
||||
const HEX_LUT: [char; 16] = [
|
||||
'0', '1', '2', '3', //
|
||||
'4', '5', '6', '7', //
|
||||
'8', '9', 'a', 'b', //
|
||||
'c', 'd', 'e', 'f', //
|
||||
];
|
||||
|
||||
fn ascii() {
|
||||
for row in 0..6 {
|
||||
for col in 0..16 {
|
||||
if col == 8 {
|
||||
print(' ')
|
||||
}
|
||||
let i = 0x20 + row * 16 + col
|
||||
print(HEX_LUT[(i >> 4) & 0xf], HEX_LUT[i & 0xf], ' ')
|
||||
}
|
||||
print(" |")
|
||||
for col in 0..16 {
|
||||
let i = 0x20 + row * 16 + col
|
||||
print(i as char)
|
||||
}
|
||||
println("|")
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user