java位运算例子
/*
一共3个移位运算符,左移位<<,右移位>>和无符号移位>>>。左移位<<在低位处补0。右移位>>若值为正则在高位插入0,若值为负则在高位插入1。无符号右移位>>>无论正负都在高位处插入0。
非运算符~
&对两个整型操作数中对应位执行布尔代数,两个位都为1时输出1,否则0。
^对两个整型操作数中对应位执行布尔代数,两个位相等0,不等1。
|对两个整型操作数中对应位执行布尔代数,两个位都为0时输出0,否则1。
*/
public class weiyunsuan {
public static void main(String[] args) {
int a=-6;// 1111 1111 1111 1111 1111 1111 1111 1010
int b=3;// 0000 0000 0000 0000 0000 0000 0000 0011
int c=6; // 0000 0000 0000 0000 0000 0000 0000 0110
zuoyi(a, b);//-48 1111 1111 1111 1111 1111 1111 1101 0000
youyi(a, b);//-1 1111 1111 1111 1111 1111 1111 1111 1111
wufuhaoyouyi(a, b);//0001 1111 1111 1111 1111 1111 1111 1111
zuoyi(c, b);//48 0000 0000 0000 0000 0000 0000 0011 0000
youyi(c, b);//0 0000 0000 0000 0000 0000 0000 0000 0000
wufuhaoyouyi(c, b);//0000 0000 0000 0000 0000 0000 0000 0000
yu(a, b);//2 0000 0000 0000 0000 0000 0000 0000 0010
huo(a, b);//-5 1111 1111 1111 1111 1111 1111 1111 1011
fei(a);//5 0000 0000 0000 0000 0000 0000 0000 0101
yihuo(a, b);//-7 1111 1111 1111 1111 1111 1111 1111 1001
}
public static void zuoyi(int a,int b){
System.out.println(a<<b);
}
public static void youyi(int a,int b){
System.out.println(a>>b);
}
public static void wufuhaoyouyi(int a,int b){
System.out.println(a>>>b);
}
public static void yu(int a,int b){
System.out.println(a&b);
}
public static void huo(int a,int b){
System.out.println(a|b);
}
public static void fei(int a){
System.out.println(~a);
}
public static void yihuo(int a,int b){
相关文档:
Java NIO API详解
在JDK
1.4以前,Java的IO操作集中在java.io这个包中,是基于流的阻塞(blocking)API。对于大多数应用来说,这样的API使用很方
便,然而,一些对性能要求较高的应用,尤其是服务端应用,往往需要一个更为有效的方式来处理IO。从JDK 1.4起,NIO
API作为一个基于缓冲区,并能提供非阻塞(non-blo ......
1
. 栈(stack)与堆(heap)都是Java用来在Ram中存放数据的地方。与C++不同,Java自动管理栈和堆,程序员不能直接地设置栈或堆。
2
. 栈的优势是,存取速度比堆要快,仅次于直接位于CPU中的寄存器。但缺点是,存在栈中的数据大小与生 ......
//计算天数
public List day(String dates,String datee) throws ParseException{
List dayls=new ArrayList();
// 字符串转换成日期
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
Date startDate = format.parse(dates);
&nb ......
public class P {
public static void main(String[] args){
String pattern="000";
java.text.DecimalFormat df = new java.text.DecimalFormat(pattern);
int i = 10,j=6;
System.out.println("i="+df.format(i)+"\nj="+df.format(j));
}
}
---------------------输出-----------------------
i=010 ......
尚学堂学习java感受
【学员故事】来自尚学堂真人真事(www.bjsxt.com)
本文作者,成,是一个幽默的学员,简单概要一下他的情况,他是数学系的,自尚学堂毕业后曾就业于文思(亚马逊)项目,现就职于亚信公司,每一次跳跃都比以前更高!
从大学毕业到再学习再到工作,刚好 ......