Avoid negative shifts in build_table()