Hacker News new | past | comments | ask | show | jobs | submit login
A branchless segment of code to generate a printable hexadecimal value (conman.org)
5 points by todsacerdoti on Feb 25, 2023 | hide | past | favorite | 1 comment



I've been playing with ARMv8 assembly lately, and printing is much more involved than it seems up front a lot of the time. Does anyone have a good algorithm for printing wider numbers with arbitrary base? How about printing numbers of arbitrary size (beyond the natural machine-width)?

I've been using a character array for my numberline (0123456789abcdef...), get dividend and remainder of number/base and increment a counter, store numbers[remainder] into a 65-byte array at the end of the array - counter, repeat until dividend and remainder are both 0, insert negative symbol if necessary, and print from the counted offset. It works, but I feel like there must be a better way.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: