You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package com.bradley.bit ;
public class Bit {
public static void printBit ( ) {
int n = 1 ;
System . out . println ( 1 < < 32 ) ;
System . out . println ( 1 < < 31 ) ;
System . out . println ( 1 < < 30 ) ;
System . out . println ( 1 < < 29 ) ;
// 1 用二进制表示 32bit ==> 00000000 00000000 00000000 00000001 1*2^0 = 1
// 1 左移32位 ==> 10000000 00000000 00000000 000000000 0*2^0 = 0
// 1 左移31位 ==> 01000000 00000000 00000000 00000000 1*2^31 = 2147483648 4294967296 超出int范围: 2147483647 变成了 -2147483648
// 1 左移30位 ==> 00100000 00000000 00000000 00000000 1*2^30 = 1
// 1 左移29位 ==> 00010000 00000000 00000000 00000000 1*2^29 = 1
}
public static void main ( String [ ] args ) {
// System.out.println(Integer.MAX_VALUE);
printBit ( ) ;
}
}