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){
相关文档:
这几天一直在搞关于优先级队列的实现,因为要考虑到线程的安全,所以PriorityQueue就不适用了。一个非常简单的实现方
法,那就是把优先级比较好的插入一个队列,优先级低的插入另一个队列,取数的时候先在优先级高的队列上取数。这有个缺点就是如果优先级别越多的话,队� ......
记得部门老大曾经说过,java的垃圾回收机制对于java体系结构的学习非常重要。这里将阅读的一些文献整理总结出来,记述java的几种垃圾回收算法。
垃圾回收算法有两个基本的问题:1.必须检测到垃圾对象。2.必须重新声明被垃圾对象占用的堆空间并且让堆空间可用。
可达性 ......
public class MyEclipseGen {
private static final String LL = "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up ......
这是服务窗口类,模拟四个线程异步运行
public class TicketWindow {
public static void main(String args[]) {
Ticket ticket = new Ticket();
Thread w1 = new Thread(ticket, "1号售票窗口");
Thread w2 = new Thread(ticket, "2号售票窗口");
Thread w3 ......