Adding binary numbers

后端 未结 21 1434
孤独总比滥情好
孤独总比滥情好 2020-11-28 07:50

Does anyone know how to add 2 binary numbers, entered as binary, in Java?

For example, 1010 + 10 = 1100.

21条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 08:11

    Martijn is absolutely correct, to piggyback and complete the answer

    Integer.toBinaryString(sum);
    

    would give your output in binary as per the OP question.

提交回复
热议问题