binary digits, added tests

moved logic to a separate method and added test