- class Test
- {
- public static void main(String [] args) throws Exception
- {
- //1.
- byte b = 8;
- int a;
- a = b;
- System.out.println(a+"..."+Integer.toBinaryString(a));
-
- //2.4byte->int,同理,int->4byte
- byte [] buf = {1,2,3,4};
- int n=0;
- for(int i=0;i<buf.length;i++)
- {
- if(i<3)
- {
- n+=buf[i];
- n=n<<8;
- }
- else
- {
- n+=buf[i];
- }
- }
- System.out.println(n+"..."+Integer.toBinaryString(n));
- }
- }
复制代码 |