Chp5: Bit Manipulation
Bits Facts and Tricks
x ^ 0s = x
x & 0s = 0
x | 0s = x
x ^ 1s = ~x
x & 1s = x
x | 1s = 1s
x ^ x = 0
x & x = x
x | x = x
Common Bit Tasks: Get, Set, Clear And Update
Get: num & (1 << i) != 0
Set: num | (1 << i)
Clear:
clear ith bit: num & (~(1 << i))
clear all bits from the most significant bit through i: num & ((1 << i) - 1)
clear all bits from i though 0: num & (~((1 << (i + 1)) - 1))
Update: (num & (~(1 << i))) | (v << i)
5.4
((n & (n - 1)) == 0) //check if n is a power of 2 (or if n is 0)
5.5 Swap odd and even bits in an integer with as few instructions ad possible.
//0xaaaaaa is 1010101010 which mask all odd bits
public int swapOddEven(int x){
return ( ((x & 0xaaaaaaaa) >> 1) | ((x & 0x55555555) << 1) );
}
Chp5: Bit Manipulation的更多相关文章
- backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.
昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec> <ctx>yMaint.ShrinkLog</ctx> ...
- Hololens开发笔记之Gesture手势识别(Manipulation手势控制物体旋转)
Manipulation gesture:保持点击手势,在3D世界中绝对运动 当你想要全息图像1:1响应用户手部移动时,操纵手势能被用于移动.缩放或旋转全息图像.如此的一个用处是使得用户可以在世界中绘 ...
- Hololens开发笔记之Gesture手势识别(Manipulation手势控制物体平移)
Manipulation gesture:保持点击手势,在3D世界中绝对运动 当你想要全息图像1:1响应用户手部移动时,操纵手势能被用于移动.缩放或旋转全息图像.如此的一个用处是使得用户可以在世界中绘 ...
- Track files and folders manipulation in Windows
The scenario is about Business Secret and our client do worry about data leakage. They want to know ...
- Data manipulation primitives in R and Python
Data manipulation primitives in R and Python Both R and Python are incredibly good tools to manipula ...
- VK Cup 2012 Qualification Round 2 C. String Manipulation 1.0 字符串模拟
C. String Manipulation 1.0 Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 codeforces.com/problemset/pr ...
- Bash String Manipulation Examples – Length, Substring, Find and Replace--reference
In bash shell, when you use a dollar sign followed by a variable name, shell expands the variable wi ...
- windows phone 之手势识别(Manipulation)
在Windows Phone 7的多触摸屏上可以检测到至少四根同时存在的手指,并且一起操作使触摸屏充分发挥效果. 在silverlight开发中通过事件来实现触屏事件的检测,包括低级别的和高级别的接口 ...
- WPF Multi-Touch 开发:高级触屏操作(Manipulation)
原文 WPF Multi-Touch 开发:高级触屏操作(Manipulation) 在上一篇中我们对基础触控操作有了初步了解,本篇将继续介绍触碰控制的高级操作(Manipulation),在高级操作 ...
随机推荐
- GDAL Configure in Visual Studio 2010 for Win7/ GDAL+VisualStudio2010 Win7 配置
配置环境: OS:Win& *86 Ultimate Edition(EN) VS:Visual Studio 2010(EN) Step1: GDAL源码下载:http://www.gisi ...
- UML类图新手入门级介绍
UML类图新手入门级介绍 举一个简单的例子,来看这样一副图,其中就包括了UML类图中的基本图示法. 首先,看动物矩形框,它代表一个类(Class).类图分三层,第一层显示类的名称,如果是抽象类,则就用 ...
- Uncaught SyntaxError: Unexpected token ILLEGAL【js错误】
应该是逗号的中英文状态错了,应该是英文状态的逗号.还有百度应用后面的逗号.college后面的冒号
- 大神是如何玩C语言的!
我在酷壳上看到一篇文章,C语言结构体里的成员数组和指针,看得感觉让我真是佩服地五体投地啊.皓哥虽说谦称自己不是高手啥的,但是写出这样的文章来,真是让我感觉自己的水平真是渣渣!我看完了感觉有点小激动,也 ...
- Centos文本方式安装情况下lvm分区的创建
作者:马 岩(Furzoom) (http://www.cnblogs.com/furzoom/)版权声明:本文的版权归作者与博客园共同所有.转载时请在明显地方注明本文的详细链接,未经作者同意请不要删 ...
- yum被锁定
使用Yum的时候 提示yum被搜定了 . Another app is currently holding the yum lock; waiting for it to exit... 解决办法 ...
- Assembly(程序集) 反射和缓存
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- h5 web模板
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --><html lang="zh-cmn-Hans"> ...
- hexo-github 博客搭建
安装nodejs 从官网下载系统对应的源码 wget -qO- https://raw.githubusercontent.com/creationix/nvm/master/install.sh | ...
- System V消息队列
消息的基本属性 System V的消息属性包含在一个msqid_ds的结构中 struct msqid_ds{ struct ipc_cerm msg_perm; //读取权限, 0644, 0777 ...