a、b、c 不是1就是0;例如:int a = 1;int b = 0;int c = 1;
byte s[] = new byte[2];因为:1 byte = 8 bit 所以初始化为0000000000000000(二进制16个0)
现在将a、b、c 三个整数转换成如下二进制: 0000000000000abc 写入s,请问如何写方法?

解决方案 »

  1.   


       String s[] = new String[2];
        s[0] = Integer.toBinaryString(a);
        s[1] = Integer.toBinaryString(b);
        s[2] = Integer.toBinaryString(c);
        //多看API呀
      

  2.   

    随便这么一敲就贴了,没在IDE里边运行~,O(∩_∩)O~
      

  3.   

    谢谢,那如何写一个方法呢?对byte[]中的二进制中的某一位进行操作。
      

  4.   


    String s[] = new String[2];
    byte b[] = new byte[2];
    b[0] = Byte.valueOf(s[0], 2);
    b[1] = Byte.valueOf(s[1], 2);
    没测试。不知道行不行。