fixed algorithm to display bits in the right order