-
Notifications
You must be signed in to change notification settings - Fork 0
Includes
Macro for printing unsigned integers in hexadecimal format:
Handles printing of both 32-bit (unsigned int
) and 64-bit (unsigned long long
) integers in hexadecimal format, ensuring compatibility by casting appropriately based on the size of the number.
Library | None (Macro definition) |
---|---|
Signature | #define print_hex(c, n) |
Parameters |
c : Specifies whether the hexadecimal output should be lowercase ('x') or uppercase ('X'). |
n : The number to be printed in hexadecimal format. |
|
Return | The number of characters printed by print_hex_varargs() function. |
print_hex('x', 12345); // Prints "3039" (hexadecimal representation of 12345)
print_hex('X', 12345); // Prints "3039" in uppercase
This macro checks the size of
n
to determine whether it's a 32-bit or 64-bit integer.
For 32-bit integers (unsigned int
), the number is cast tounsigned long long
to ensure consistency.
Calls theprint_hex_varargs()
function, passing the format specifier (c
) and the properly cast number.
Works for bothunsigned int
andunsigned long long
types without requiring manual casting by the user.
Automatically casts smaller integers (32-bit) tounsigned long long
, ensuring compatibility withprint_hex_varargs()
function.
Previous ⬅️ • Top ⬆️ •