2 * Copyright 2007 Google Inc.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
17 package com.google.zxing.common;
\r
20 * <p>A simple, fast array of bits, represented compactly by an array of ints internally.</p>
\r
22 * @author srowen@google.com (Sean Owen)
\r
24 public final class BitArray {
\r
26 private final int[] bits;
\r
28 public BitArray(int size) {
\r
29 int arraySize = size >> 5;
\r
30 if ((size & 0x1F) != 0) {
\r
33 bits = new int[arraySize];
\r
37 * @param i bit to get
\r
38 * @return true iff bit i is set
\r
40 public boolean get(int i) {
\r
41 return (bits[i >> 5] & (1 << (i & 0x1F))) != 0;
\r
47 * @param i bit to set
\r
49 public void set(int i) {
\r
50 bits[i >> 5] |= 1 << (i & 0x1F);
\r
54 * Sets a block of 32 bits, starting at bit i.
\r
56 * @param i first bit to set
\r
57 * @param newBits the new value of the next 32 bits. Note again that the least-significant bit
\r
58 * correponds to bit i, the next-least-significant to i+1, and so on.
\r
60 public void setBulk(int i, int newBits) {
\r
61 bits[i >> 5] = newBits;
\r
65 * Clears all bits (sets to false).
\r
67 public void clear() {
\r
68 int max = bits.length;
\r
69 for (int i = 0; i < max; i++) {
\r
75 * @return underlying array of ints. The first element holds the first 32 bits, and the least
\r
76 * significant bit is bit 0.
\r
78 public int[] getBitArray() {
\r