> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/api-reference/ks.reactor/ks.reactor.ksbitwriter.md).

# Class ksBitWriter

Namespace: [KS.Reactor](/reactor/api-reference/ks.reactor.md)\
Assembly: KSCommon.dll

Writes bit-packed data to a [ksStreamBuffer](/reactor/api-reference/ks.reactor/ks.reactor.ksstreambuffer.md). When you are done writing all your data, you must call [Flush](#KS_Reactor_ksBitWriter_Flush) to ensure the last byte of data is written. Read the data using a [ksBitReader](/reactor/api-reference/ks.reactor/ks.reactor.ksbitreader.md).

```csharp
public class ksBitWriter
```

#### Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) â† [ksBitWriter](/reactor/api-reference/ks.reactor/ks.reactor.ksbitwriter.md)

#### Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object\)), [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals\(system-object-system-object\)), [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode), [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype), [object.MemberwiseClone()](https://learn.microsoft.com/dotnet/api/system.object.memberwiseclone), [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals), [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Constructors

### ksBitWriter(ksStreamBuffer) <a href="#ks_reactor_ksbitwriter__ctor_ks_reactor_ksstreambuffer" id="ks_reactor_ksbitwriter__ctor_ks_reactor_ksstreambuffer"></a>

Constructor

```csharp
public ksBitWriter(ksStreamBuffer buffer)
```

#### Parameters

`buffer` [ksStreamBuffer](/reactor/api-reference/ks.reactor/ks.reactor.ksstreambuffer.md)

Buffer to write to.

## Methods

### Flush() <a href="#ks_reactor_ksbitwriter_flush" id="ks_reactor_ksbitwriter_flush"></a>

Flushes the current byte to the buffer. Subsequent writes will write to the next byte.

```csharp
public void Flush()
```

### Write(bool) <a href="#ks_reactor_ksbitwriter_write_system_boolean" id="ks_reactor_ksbitwriter_write_system_boolean"></a>

Writes 1 bit to the buffer.

```csharp
public void Write(bool value)
```

#### Parameters

`value` [bool](https://learn.microsoft.com/dotnet/api/system.boolean)

Value to write. True = 1, False = 0.

### WriteBits(uint, int) <a href="#ks_reactor_ksbitwriter_writebits_system_uint32_system_int32" id="ks_reactor_ksbitwriter_writebits_system_uint32_system_int32"></a>

Writes up to 32 bits into the buffer.

```csharp
public void WriteBits(uint input, int bits)
```

#### Parameters

`input` [uint](https://learn.microsoft.com/dotnet/api/system.uint32)

input to write bits from.

`bits` [int](https://learn.microsoft.com/dotnet/api/system.int32)

number of bits from input to write.

### WriteBits64(ulong, int) <a href="#ks_reactor_ksbitwriter_writebits64_system_uint64_system_int32" id="ks_reactor_ksbitwriter_writebits64_system_uint64_system_int32"></a>

Writes up to 64 bits into the buffer.

```csharp
public void WriteBits64(ulong input, int bits)
```

#### Parameters

`input` [ulong](https://learn.microsoft.com/dotnet/api/system.uint64)

input to write bits from.

`bits` [int](https://learn.microsoft.com/dotnet/api/system.int32)

number of bits from input to write.
