Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I ended up writing my own, so here they are.</p> <p>The BinaryWriter (I've only overridden the ones that I needed)</p> <pre><code>private class BinaryWriter : System.IO.BinaryWriter { private bool[] curByte = new bool[8]; private byte curBitIndx = 0; private System.Collections.BitArray ba; public BinaryWriter(Stream s) : base(s) { } public override void Flush() { base.Write(ConvertToByte(curByte)); base.Flush(); } public override void Write(bool value) { curByte[curBitIndx] = value; curBitIndx++; if (curBitIndx == 8) { base.Write(ConvertToByte(curByte)); this.curBitIndx = 0; this.curByte = new bool[8]; } } public override void Write(byte value) { ba = new BitArray(new byte[] { value }); for (byte i = 0; i &lt; 8; i++) { this.Write(ba[i]); } ba = null; } public override void Write(byte[] buffer) { for (int i = 0; i &lt; buffer.Length; i++) { this.Write((byte)buffer[i]); } } public override void Write(uint value) { ba = new BitArray(BitConverter.GetBytes(value)); for (byte i = 0; i &lt; 32; i++) { this.Write(ba[i]); } ba = null; } public override void Write(ulong value) { ba = new BitArray(BitConverter.GetBytes(value)); for (byte i = 0; i &lt; 64; i++) { this.Write(ba[i]); } ba = null; } public override void Write(ushort value) { ba = new BitArray(BitConverter.GetBytes(value)); for (byte i = 0; i &lt; 16; i++) { this.Write(ba[i]); } ba = null; } private static byte ConvertToByte(bool[] bools) { byte b = 0; byte bitIndex = 0; for (int i = 0; i &lt; 8; i++) { if (bools[i]) { b |= (byte)(((byte)1) &lt;&lt; bitIndex); } bitIndex++; } return b; } } </code></pre> <p>And, the BinaryReader, once again, I've only overridden the methods that I needed.</p> <pre><code>private class BinaryReader : System.IO.BinaryReader { private bool[] curByte = new bool[8]; private byte curBitIndx = 0; private BitArray ba; public BinaryReader(Stream s) : base(s) { ba = new BitArray(new byte[] { base.ReadByte() }); ba.CopyTo(curByte, 0); ba = null; } public override bool ReadBoolean() { if (curBitIndx == 8) { ba = new BitArray(new byte[] { base.ReadByte() }); ba.CopyTo(curByte, 0); ba = null; this.curBitIndx = 0; } bool b = curByte[curBitIndx]; curBitIndx++; return b; } public override byte ReadByte() { bool[] bar = new bool[8]; byte i; for (i = 0; i &lt; 8; i++) { bar[i] = this.ReadBoolean(); } byte b = 0; byte bitIndex = 0; for (i = 0; i &lt; 8; i++) { if (bar[i]) { b |= (byte)(((byte)1) &lt;&lt; bitIndex); } bitIndex++; } return b; } public override byte[] ReadBytes(int count) { byte[] bytes = new byte[count]; for (int i = 0; i &lt; count; i++) { bytes[i] = this.ReadByte(); } return bytes; } public override ushort ReadUInt16() { byte[] bytes = ReadBytes(2); return BitConverter.ToUInt16(bytes, 0); } public override uint ReadUInt32() { byte[] bytes = ReadBytes(4); return BitConverter.ToUInt32(bytes, 0); } public override ulong ReadUInt64() { byte[] bytes = ReadBytes(8); return BitConverter.ToUInt64(bytes, 0); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload