str位数不足时,如果左补‘0’则补ASCII表示的‘0’,如果右补‘0’则补二进制表示的‘0’
怎么搞啊,各位帮帮忙

解决方案 »

  1.   

    byte 的范围是从-127-128
    我想问你你的i你要怎么转?
      

  2.   

    String s="abcd";
    int i = 123456;
    首先先把i分割,2位分割
    你的i最多只能到8位。
    int[] itemp=new int[4];
    byte[] by=new byte[10];
    for(int j=0;j<4;j++){
    itemp[j]=i-((i/is)*100);
    i/=100;
    }
    for(int j=0;j<4;j++){
       by[j]=(byte)it[j];
    }
    byte[] st=s.getBytes();
    if(st.length>6){
       System.err.println("字符串s转换成byte后长度超过");
    }
    for(int j=0;j<st.length;j++){
    byte[4+j]=st[j];
    }
      

  3.   

    Byte[] bytes;
    bytes[0] = i;
    bytes[1] = i >> 8;
    bytes[2] = i >> 16;
    bytes[3] = i >> 24;
    system.arraycopy(str.getBytes[], 0, bytes, 4, str.getBytes[].length)没调的,自己看看吧
      

  4.   

    System.out.println(Integer.toBinaryString(123456));
    结果:11110001001000000以下转换函数
    static byte[] int2bytes(int num){
        byte[] b=new byte[4];
        for(int i=0;i<4;i++){
            b[i]=(byte)(num>>>(24-i*8));
        }
        return b;
    }
    调用函数:int2bytes(123456)
    结果: 0  1  -30   64