How to convert a long to a fixed-length 16-bit binary string?

前端 未结 8 1021
谎友^
谎友^ 2020-12-10 17:23

Hi i want to convert a long integer to binary but the problem is i want a fixed 16 bit binary result after conversion like if i convert 2 to 16 bit binary it should give me

8条回答
  •  一整个雨季
    2020-12-10 17:48

    Binary is a representation and not a format to convert an integer to. For example, if you have an integer:

    int i = 2;
    

    The binary representation will be 00000010. Java has only signed integers, so this link will be helpful.

提交回复
热议问题