⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cb8583bitmap.java

📁 8583 pack and unpack 8583 pro
💻 JAVA
字号:
package com.szzt.trade.zsbank;
import com.szzt.common.datapacket.PacketException;

public class CB8583Bitmap {
  private byte[] bitmapArray = new byte[16];
  private static byte[] workMask=null;
  static {
      workMask=new byte[8];
      workMask[0]=(byte)0x80;
      workMask[1]=(byte)0x40;
      workMask[2]=(byte)0x20;
      workMask[3]=(byte)0x10;
      workMask[4]=(byte)0x08;
      workMask[5]=(byte)0x04;
      workMask[6]=(byte)0x02;
      workMask[7]=(byte)0x01;
  }


  public CB8583Bitmap() {
    for (int i=0;i<bitmapArray.length;i++)
      this.bitmapArray[i]=0x00;
  }

  public void clear(){
    for (int i=0;i<bitmapArray.length;i++)
      this.bitmapArray[i]=0x00;
  }

  public byte[] getBitmap() {
    return this.bitmapArray;
  }

  public void setBitmap(byte[] newValue) throws PacketException{
    if (newValue==null)
      throw new PacketException("设置8583位图出错");
    if (newValue.length != 16)
      throw new PacketException("设置8583位图出错");
    this.bitmapArray=newValue;
  }

  public void openBit(int bitIndex) throws PacketException {
    if (bitIndex<=0 || bitIndex>128)
      throw new PacketException("设置8583位图出错");

    if (bitIndex % 8==0)
      this.bitmapArray[bitIndex/8-1] |= workMask[7];
   else
      this.bitmapArray[bitIndex/8] |= workMask[bitIndex%8-1];
  }

  public void closeBit(int bitIndex) throws PacketException {
    if (bitIndex<=0 || bitIndex>128)
      throw new PacketException("设置8583位图出错");

    if (bitIndex % 8==0)
      this.bitmapArray[bitIndex/8-1] &= ~workMask[7];
    else
      this.bitmapArray[bitIndex/8] &= ~workMask[bitIndex%8-1];
  }

  public void convertBit(int bitIndex) throws PacketException {
    if (bitIndex<=0 || bitIndex>128)
      throw new PacketException("设置8583位图出错");

    if (isBitSet(bitIndex))
      closeBit(bitIndex);
    else
      openBit(bitIndex);
  }


  public boolean isBitSet(int bitIndex) {
    if (bitIndex<=0 || bitIndex>128)
      return false;

    if (bitIndex % 8==0){
      if ((this.bitmapArray[bitIndex/8-1] & workMask[7])!=0x00)
        return true;
      else
        return false;
    }
    else {
      if ((this.bitmapArray[bitIndex/8] & workMask[bitIndex%8-1]) != 0x00)
        return true;
      else
        return false;
    }
  }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -