📄 asnbitstring.java
字号:
/** * * AsnBitString : A utility class representing an ASN bit string * * @author Ian Ibbotson ( ibbo@k-int.com ) * @version $Id: AsnBitString.java,v 1.2 2000/12/23 10:44:33 ianibbo Exp $ * * Copyright: Copyright (C) 2000, Knowledge Integration Ltd. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public License * as published by the Free Software Foundation; either version 2.1 of * the license, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite * 330, Boston, MA 02111-1307, USA. * */package com.k_int.codec.runtime;public class AsnBitString{ public int numbytes=0; public int unused_bits = 0; public byte[] value = null; public AsnBitString() { // Default to 8 bits of data, we can always grow later... numbytes=1; value = new byte[1]; } public AsnBitString(byte[] bits, int unused) { value = bits; unused_bits = unused; } public AsnBitString(int top_bit_pos) { // Allocate the value buffer based on the top bit position... numbytes = top_bit_pos / 8; numbytes += ( top_bit_pos % 8 > 0 ? 1 : 0 ); value = new byte[numbytes]; } byte[] getValue() { return value; } // Set a specific bit position public void setBit(int bitpos) { int num_bytes_needed = (bitpos+1) / 8; num_bytes_needed += ( (bitpos+1) % 8 > 0 ? 1 : 0 ); // System.err.println("setBit request to set bit at pos "+bitpos); // System.err.println("setBit num_bytes_needed = "+num_bytes_needed+" current = "+numbytes); if ( num_bytes_needed > numbytes ) { // System.err.println("re-allocating bitstring"); // We need to re-allocate the buffer byte [] newvalue = new byte[num_bytes_needed]; if ( null != value ) System.arraycopy(value, 0, newvalue, 0, numbytes); numbytes = num_bytes_needed; value = newvalue; } // Figure out which octet contains the bit we need to set, and what // position in that octet int octet_to_set = bitpos / 8; int bit_to_set = 7 - ( bitpos % 8 ); // int bit_to_set = 8 - ( bitpos % 8 ); value[octet_to_set] |= ( 1 << bit_to_set ); // System.err.println("After anding bit "+bit_to_set+" of octet "+octet_to_set+" with "+(1 << bit_to_set)+"value = "+value[octet_to_set]); } // Check a specific bit position public void isBitSet(int bitpos) { }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -