How to display the value of bitfiled in hex? #2120
Answered
by
WerWolv
cpcopy
asked this question in
Pattern Language Q&A
-
I just found a way to use type::hex to convert unsiged data type as below. But it doesn't work for bitfied data type. According to the example in guide, it can be hex value. |
Beta Was this translation helpful? Give feedback.
Answered by
WerWolv
Feb 18, 2025
Replies: 1 comment 1 reply
-
Hey, that image is somewhat old, we used to always display both decimal and hex values for integers. import std.io;
fn format_hex(auto value) {
return std::format("0x{:02X}", value);
};
bitfield Test {
unsigned value : 8 [[format("format_hex")]];
};
Test test @ 0x00; |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
WerWolv
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, that image is somewhat old, we used to always display both decimal and hex values for integers.
You can however still simply use a format function: