forked from WerWolv/ImHex-Patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bcd.pat
37 lines (26 loc) · 727 Bytes
/
bcd.pat
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#pragma once
#include <std/io.pat>
/*!
Type to decode a BCD (Binary Coded Decimal) number
*/
namespace type {
/**
Decodes a BCD value where one byte represents a single digit
@tparam Digits Number of digits
*/
struct BCD<auto Digits> {
u8 bytes[Digits];
} [[sealed, format_read("type::impl::format_bcd")]];
namespace impl {
fn format_bcd(ref auto bcd) {
str result;
for (u32 i = 0, i < sizeof(bcd.bytes), i += 1) {
u8 byte = bcd.bytes[i];
if (byte >= 10)
return "Invalid";
result += std::format("{}", byte);
}
return result;
};
}
}