int s=123;
short ss=(short)s;

解决方案 »

  1.   

    不好意思。我还是没看清楚你提的问题到底什么意思看来我的智商有问题。。sorry.还请智商比较高的人来帮你解答把。
      

  2.   

    int num = 32767;
         byte[] ba = new byte[2];
         ba[0] = (byte) ((num >> 8) & 0xFF);
         ba[1] = (byte) (num & 0xFF);
        
         short s =  (short)(ba[0] << 8 & 0xFF00 | ba[1] & 0x00FF);
         System.out.println(s);
      

  3.   

    int ch1 = read();
            int ch2 = read();
            if ((ch1 | ch2) < 0)
                throw new EOFException();
            return (short)((ch1 << 8) + (ch2 << 0));