bt[0] = (byte) 192;  //最大是127,但你考虑负啊
    bt[1] = 0;
    bt[2] = 0;
    bt[3] = 1;

解决方案 »

  1.   

    InetAddress本身不是有一个getByName的方法初始化字符串吗?string a="192.0.0.1";
    InetAddress address = null;
    try {
    address = InetAddress.getByName(a);
    }
    catch (UnknownHostException ex) {
    }
    不过要求a是有效地址,否则会抛exception
    getByAddress就不清楚了
      

  2.   

    不知道你对位运算是否了解你传的参数最后jdk中的使用方式是
    int address;
    if (addr != null) {
        if (addr.length == 4) {
    address  = addr[3] & 0xFF;
    address |= ((addr[2] << 8) & 0xFF00);
    address |= ((addr[1] << 16) & 0xFF0000);
    address |= ((addr[0] << 24) & 0xFF000000);
        } 

    所以传addr[0] = (byte) 192; 
        addr[1] = 0;
        addr[2] = 0;
        addr[3] = 1;
    就可以了。
      

  3.   

    确保a的合法性
    对每个b[i]=(b[i]<=127)?b[i]:b[i]-256即可^_^
      

  4.   

    byte 是8位,只有在表示有符号数时最大才是127
    无符号的是255 !!!