use bitwise operations for encoding/decoding the first nibble

comparing with >= 2 isn't a natural way to check if the second bit is
set and it's also wrong if higher bits could be set