cast-number-to-hex-string

gweimer/utils/cast-number-to-hex-string

Convert NUM to a HEX string with "0x" prefix and a minimum of DIG digits (use leading 0's to fill).
cast-number-to-hex-string
@/cast-number-to-hex-string
Convert NUM to a HEX string with "0x" prefix and a minimum of DIG digits (use leading 0's to fill).
NUMnumber
Number to print in HEX
DIGnumber
Minimum number of HEX digits to print (use leading zeros to pad)
cast-number-to-hex-string
OUT
NUM
DIG
OUTstring
To use the node in your project you should have the gweimer/utils library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.

C++ implementation

struct State {
    char str[16];
    CStringView view;
    State() : view(str) { }
};

{{ GENERATED_CODE }}

void evaluate(Context ctx) {
    auto state = getState(ctx);
    auto inValue = getValue<input_NUM>(ctx);
    char fmt[10];
    sprintf(fmt, "0x%%0%uX", int(getValue<input_DIG>(ctx)));
    sprintf(state->str, fmt, int(inValue));
    emitValue<output_OUT>(ctx, XString(&state->view));
}