java实现BitMap
来源:互联网 发布:淘宝全景图怎么做 编辑:程序博客网 时间:2024/06/05 16:33
package bitmap;public class BitMap {private byte[] bytes;public BitMap(byte[] bytes) {super();this.bytes = bytes;}public BitMap() {super();}public BitMap(int size) {super();int number = size / 8 + 1;// may waste a byte, which does not matterbytes = new byte[number];}/** * * @param n * n>=1 */public void setBit(int n) {if (n <= 0)return;int index = -1;int offset = -1;if (0 == n % 8) {index = n / 8 - 1;offset = 7;} else {index = n / 8;offset = n % 8 - 1;}switch (offset) {case 0:bytes[index] = (byte)(bytes[index]|0x01);break;case 1:bytes[index] = (byte)(bytes[index]|0x02);break;case 2:bytes[index] = (byte)(bytes[index]|0x04);break;case 3:bytes[index] = (byte)(bytes[index]|0x08);break;case 4:bytes[index] = (byte)(bytes[index]|0x10);break;case 5:bytes[index] = (byte)(bytes[index]|0x20);break;case 6:bytes[index] = (byte)(bytes[index]|0x40);break;case 7:bytes[index] = (byte)(bytes[index]|0x80);break;}}public boolean get(int n){if (n <= 0)return false;int index = -1;int offset = -1;if (0 == n % 8) {index = n / 8 - 1;offset = 7;} else {index = n / 8;offset = n % 8 - 1;}switch (offset) {case 0:return (byte)(bytes[index]&0x01)!=0;//2^0case 1:return (byte)(bytes[index]&0x02)!=0;case 2:return (byte)(bytes[index]&0x04)!=0;case 3:return (byte)(bytes[index]&0x08)!=0;case 4:return (byte)(bytes[index]&0x10)!=0;case 5:return (byte)(bytes[index]&0x20)!=0;case 6:return (byte)(bytes[index]&0x40)!=0;case 7:return (byte)(bytes[index]&0x80)!=0;}return false;}public static void main(String[] args) {BitMap bMap = new BitMap(60);bMap.setBit(59);bMap.setBit(20);bMap.setBit(21);for(int i=1;i<=60;i++){if(bMap.get(i)==true)System.out.println(i);}}}
0 0
- java bitmap实现
- java实现Bitmap算法
- BitMap的java实现
- java实现BitMap
- java bitmap 实现
- Bitmap java实现
- java中BitMap实现
- Java实现2-BitMap排序
- BitMap实现
- java/bitmap
- bitmap与2bitmap实现
- bitmap与2bitmap实现
- bitmap与2bitmap实现
- bitmap思想及其在java中的相关实现
- bitmap思想及其在java中的相关实现
- python实现bitmap原理
- C实现bitmap位图
- C实现bitmap位图
- 指针函数与函数指针的区别
- C++的文件操作
- 启动 Eclipse 弹出“Failed to load the JNI shared library jvm.dll”错误的解决方法! .
- excel数据导入导出SQL Server 2005
- 一点关于网络的小问题
- java实现BitMap
- <自己动手写操作系统>第三章——pmtest3源码解析:使用LDT
- NRV RVO
- 感兴趣的文章和专家(作业)
- 喜欢的专家
- 恢复windowXP欢迎登录界面
- 如何书写高质量的jQuery代码
- eclipse ctrl+shift+f 把方法参数直接format成一竖排
- 【php学习】超长隐藏