---
Product: Aspose.PDF
Platform: net
Page Type: reference
Canonical URL: https://reference.aspose.org/pdf/net/BitString
---

# BitString

## Overview

`BitString` is a class in Aspose.PDF FOSS for .NET.
Inherits from: `IEquatable`.

A variable-length bit string supporting bitwise operations, concatenation, substring extraction, and conversion to/from bytes and hex.

This class provides 35 methods for working with BitString objects in .NET programs.
Available methods include: `And`, `BitString`, `Concatenate`, `Empty`, `Equals`, `FromBitsString`, `FromBytesBuffer`, `FromHexString`, `Get64Bits`, `GetHashCode`, `Not`, `One`, and 11 additional methods.
All public members are accessible to any .NET application after installing the Aspose.PDF FOSS for .NET package.
Properties: `Length`.

## Properties

| Name | Type | Access | Description |
|------|------|--------|-------------|
| `Length` | `int` | Read | Number of bits. |

## Methods

| Signature | Description |
|-----------|-------------|
| `BitString(length: int)` | Create a zero-filled BitString of the given length. |
| `BitString(length: int, fill: bool)` | Create a BitString of the given length filled with 0 or 1. |
| `BitString(bytes: byte[])` | Create from a byte array (bytes in reverse order: last byte → leftmost bits). |
| `BitString(bytes: byte[], minBitLength: int, totalBitLength: int)` | Create from bytes with trim to minBitLength then left-pad to totalBitLength. |
| `BitString(source: BitString)` | Copy an existing BitString and prepend padding zero bits. |
| `BitString(source: BitString, padding: int)` | Copy an existing BitString and prepend padding zero bits. |
| `Empty()` | Calls Empty on this BitString instance. |
| `Zero()` | Calls Zero on this BitString instance. |
| `One()` | Calls One on this BitString instance. |
| `Zeroes(count: int)` | Calls Zeroes on this BitString instance. |
| `Ones(count: int)` | Calls Ones on this BitString instance. |
| `FromBitsString(s: string)` | Calls FromBitsString on this BitString instance. |
| `FromHexString(hex: string, bitLength: int?)` | Parse from hex string (big-endian bytes), optionally trim to bitLength LSBs. |
| `FromBytesBuffer(buffer: byte[], offset: int, count: int)` | Calls FromBytesBuffer on this BitString instance. |
| `ToString()` | Binary string of '0' and '1' (leftmost = MSB = bit (Length-1)). |
| `ToHexByteString()` | Hex byte string (same byte order as constructor: byte[0] is LSB → "0d19ff20"). |
| `ToBytes()` | Convert to byte array. |
| `Equals(other: BitString?)` | Calls Equals on this BitString instance. |
| `Equals(obj: object?)` |  |
| `GetHashCode()` | Calls GetHashCode on this BitString instance. |
| `Xor(a: BitString, b: BitString)` | Calls Xor on this BitString instance. |
| `Xor(other: BitString)` |  |
| `Or(a: BitString, b: BitString)` | Calls Or on this BitString instance. |
| `Or(other: BitString)` |  |
| `And(a: BitString, b: BitString)` | Calls And on this BitString instance. |
| `And(other: BitString)` |  |
| `Not(a: BitString)` | Calls Not on this BitString instance. |
| `Not()` |  |
| `Concatenate(a: BitString, b: BitString)` | Static: result = b bits followed by a bits (b is prepended). |
| `Concatenate(other: BitString)` | In-place: prepend other bits before this. |
| `Substring(startFromEnd: int)` | Extract all bits except the last startFromEnd bits. |
| `Substring(startFromEnd: int, count: int)` | Extract count bits starting at position (Length - startFromEnd - count). |
| `PadWithZeroes(count: int)` | Prepend count zero bits. |
| `Get64Bits(pos: int)` | Read 64 bits starting at bit position pos (must be multiple of 64). |
| `Set64Bits(pos: int, value: ulong)` | Write 64 bits starting at bit position pos (must be multiple of 64). |

## See Also

- [Aspose.PDF for .NET — Enterprise API Reference](https://reference.aspose.com/pdf/net/)