int a,b;
float c;
如何把8个字节的Long转成2个4个字节的int保存呢?
请详细说明..谢谢!!

解决方案 »

  1.   

    long a;
    int b,c;
    c = (int)a ;得到a的后4个字节
    b = a>>32 ; 向右移动32位,得到前4个字节
      

  2.   

    public class test1 { 
       public static void main(String[] args) { 
          long a=21115111111L;
          int x=-1; 
          //打印a的二进制表示     
          for(int i = 63; i >= 0; i--){
              if(((1L << i) & a) != 0)
                System.out.print("1");
              else
                System.out.print("0");        
          }
          System.out.println();
          int b,c;
          b=(int) (a&x);        
         c=(int)((a>>32)&x);
         ////打印c的二进制表示
         for(int j = 31; j >= 0; j--)
             if(((1 << j) &  c) != 0)
               System.out.print("1");
             else
               System.out.print("0");
         System.out.println();
    //打印b的二进制表示 
         for(int j = 31; j >= 0; j--)
             if(((1 << j) &  b) != 0)
               System.out.print("1");
             else
               System.out.print("0");
          System.out.println();       
          System.out.println(b);
          System.out.println(c);   
          
       } 
    } 0000000000000000000000000000010011101010100011110000011011000111
    00000000000000000000000000000100
    11101010100011110000011011000111
    -359725369
    4
      

  3.   

    楼上的方法肯定不行
    关注ing