Skip to content
Iva edited this page Sep 27, 2024 · 2 revisions

print_hex_rec

Recursively prints a number in hexadecimal format:
Converts the given number to its hexadecimal representation, printing digits and letters (a-f or A-F) in the correct order.

Original Function:

Library None (Internal helper function)
Signature int print_hex_rec(unsigned long long n, char c);
Parameters n: The number to be printed in hexadecimal.
c: Specifies whether the letters in the hexadecimal output should be lowercase (x) or uppercase (X).
Return The number of characters printed.

Usage Example:

int printed = print_hex_rec(255, 'x'); // Prints "ff"

Specifics:

Uses recursion to divide the number by 16, printing the remainders in reverse order.
Handles lowercase and uppercase hexadecimal letters.


print_hex_varargs

Handles variadic arguments to print a number in hexadecimal format:
Converts an unsigned long long number to hexadecimal, printing it with either lowercase (%x) or uppercase (%X) letters based on the format specifier.

Original Function:

Library <stdarg.h>
Signature int print_hex_varargs(int c, ...);
Parameters c: Specifies whether the hexadecimal output should use lowercase ('x') or uppercase ('X').
...: Variadic arguments containing the unsigned long long number to be printed.
Return The number of characters printed.

Usage Example:

int printed = print_hex_varargs('x', 255); // Prints "ff" and returns 2
int printed_upper = print_hex_varargs('X', 255); // Prints "FF" and returns 2

Specifics:

Calls print_hex_rec to recursively convert and print the number in hexadecimal format.
Supports both lowercase ('x') and uppercase ('X') hexadecimal formats based on the c parameter.
If n == 0, print_hex_rec will handle the printing of "0".

Previous ⬅️ Top ⬆️ Next ➡️

Clone this wiki locally