Sort out bits/bytes confusion

Add units of measure for bits and bytes and tidy up code around
bits/bytes conversions.  Also widen some unit test margins for tests
that were probabilistically failing.