Fixed logic for binary conversion