summaryrefslogtreecommitdiff
path: root/ft_puthexlower.c
diff options
context:
space:
mode:
authoryctct <yctct>2026-01-28 12:43:28 +0100
committeryctct <yctct>2026-01-28 12:43:28 +0100
commit925989f7e7af67d965e2b501a51068acfe449ab0 (patch)
tree7a83e51d2872f9c97abf3166f883ff8dfcf7e2e0 /ft_puthexlower.c
Add all files, first commit
Diffstat (limited to 'ft_puthexlower.c')
-rw-r--r--ft_puthexlower.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/ft_puthexlower.c b/ft_puthexlower.c
new file mode 100644
index 0000000..282328a
--- /dev/null
+++ b/ft_puthexlower.c
@@ -0,0 +1,30 @@
+
+// parameter is unsigned long so function does not
+// overflow when LONG_MAX is the address
+// we use recursion to print backwards
+
+#include "ft_printf.h"
+
+int ft_puthexlower(unsigned long n)
+{
+ const char hex[16] = "0123456789abcdef";
+ int save;
+ int remainder;
+ int counter;
+
+ remainder = 0;
+ save = 0;
+ counter = 0;
+ if (n > 15)
+ {
+ save = n;
+ n /= 16;
+ remainder = save - (n * 16);
+ counter += ft_puthexlower(n);
+ counter += write(1, &hex[remainder], 1);
+ }
+ else
+ counter += write(1, &hex[n], 1);
+ return (counter);
+}
+