Skip to content

Includes

Iva edited this page Sep 27, 2024 · 2 revisions

print_hex (Macro)

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.

Original Macro:

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.

Usage Example:

print_hex('x', 12345);   // Prints "3039" (hexadecimal representation of 12345)
print_hex('X', 12345);   // Prints "3039" in uppercase

Specifics:

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 to unsigned long long to ensure consistency.
Calls the print_hex_varargs() function, passing the format specifier (c) and the properly cast number.
Works for both unsigned int and unsigned long long types without requiring manual casting by the user.
Automatically casts smaller integers (32-bit) to unsigned long long, ensuring compatibility with print_hex_varargs() function.

Previous ⬅️ Top ⬆️

Clone this wiki locally