Skip to content

Commit d248f48

Browse files
committed
Update hex.ds
1 parent e4cb939 commit d248f48

1 file changed

Lines changed: 4 additions & 49 deletions

File tree

src/hex.ds

Lines changed: 4 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,4 @@
1-
// XDV Kernel: Hex Encoding Utilities
2-
// Simple hex encoding for debug output and addresses
3-
4-
forge Hex {
5-
proc K::encode_u64(K[u64] val) -> K[String] {
6-
mut let out: K[String] = "";
7-
mut let v: K[u64] = val;
8-
mut let shift: K[u64] = 60;
9-
10-
while shift >= 0 {
11-
let nibble: K[u8] = ((v >> shift) & 0xF) as K[u8];
12-
let hex_char: K[String] = @to_hex_char(nibble);
13-
out = out + hex_char;
14-
if shift == 0 {
15-
break;
16-
}
17-
shift = shift - 4;
18-
}
19-
20-
out
21-
}
22-
23-
proc K::encode_u32(K[u32] val) -> K[String] {
24-
encode_u64(val as K[u64])
25-
}
26-
27-
proc K::encode_bytes(K[Ptr[u8]] ptr, K[u64] len) -> K[String] {
28-
mut let result: K[String] = "";
29-
mut let i: K[u64] = 0;
30-
let mut bytes_left: K[u64] = len;
31-
32-
while i < len {
33-
let byte: K[u8] = unsafe_load_u8(ptr + i);
34-
result = result + encode_u32(byte as K[u32]);
35-
i = i + 1;
36-
}
37-
38-
result
39-
}
40-
41-
proc K::to_hex_char(K[u8] nibble) -> K[String] {
42-
const HEX: K[String] = "0123456789abcdef";
43-
unsafe_substring(HEX, nibble as K[u64], 1)
44-
}
45-
46-
proc K::unsafe_substring(K[String] s, K[u64] pos, K[u64] len) -> K[String] {
47-
@substr(s, pos, len)
48-
}
49-
}
1+
// XDV Kernel: Hex Encoding
2+
K hex_digit(K[Int] n) -> K[Int] {
3+
n & 15
4+
}

0 commit comments

Comments
 (0)