This looks reasonable to me, with the exception of UB on left shift of negative signed values. Please compile with -fsanitize=address,undefined then exercise the code to catch errors. -- Alan Modra Australia Development Lab, IBM