You could use 16 counters to help work this out.