/* * int name * int description * int24 offset * int8 type * int childCount * int childOffset * int optionCount * int optionOffset * int maxElements * int size * int nextSiblingOffset */ public Field(EndianReader er) { int pos = er.Position; name = er.ReadString(er.ReadInt24()); description = er.ReadString(er.ReadInt24()); Int24 int24 = er.ReadInt24(); offset = int24.Integer; type = (FieldType)int24.Byte; children = new Field[er.ReadInt32()]; fieldOffset = er.ReadInt32(); er.Position = fieldOffset; for (int x = 0; x < children.Length; x++) { children[x] = new Field(er); } er.Position = pos + 20; options = new string[er.ReadInt32()]; optionOffset = er.ReadInt32(); er.Position = optionOffset; for (int x = 0; x < options.Length; x++) { options[x] = er.ReadString(er.ReadInt24()); } er.Position = pos + 28; maxCount = er.ReadInt32(); size = er.ReadInt32(); nextOffset = er.ReadInt32(); er.Position = nextOffset; }
public static RoleTest Read(byte[] buffer, int offset) { var msg = new RoleTest(); msg.RoleId = BitConverter.ToInt16(buffer, offset); offset += 2; var RoleNameLength = buffer[offset]; offset++; msg.RoleName = StringEncoding.GetString(buffer, offset, RoleNameLength); offset += RoleNameLength; msg.Id = Int24.ReadInt24(buffer, offset); offset += 3; var countIds = buffer[offset]; offset++; var listIds = new List <int>(); for (var i = 0; i < countIds; i++) { var item = Int24.ReadInt24(buffer, offset); offset += 3; listIds.Add(item); } msg.Ids = listIds; return(msg); }
public bool Acknowledge(Int24 datagramSequenceNumber) { var sequence = datagramSequenceNumber.IntValue(); OutgoingAckQueue.Enqueue(sequence); var lastDatagram = Interlocked.Read(ref _lastDatagramSequenceNumber); if (sequence > lastDatagram) { var last = Interlocked.CompareExchange(ref _lastDatagramSequenceNumber, sequence, lastDatagram); var skipped = sequence - last - 1; if (skipped > 0) { for (long i = last; i < sequence; i++) { if (_nacked.TryAdd((int)i)) { OutgoingNackQueue.Enqueue((int)i); } } } return(true); } return(false); }
public static void TestValidValuesFromInt(Int32 value) { TestHelpers.CatchUnexpected(() => { Int24 val = Int24.GetNew(value); Assert.AreEqual(value, val.Value, string.Format("On Set with Int32:{0}", value)); }); }
public void T09_Int24_CompareTo_Sorted() { Int24[] array = new Int24[6] { new Int24(25), new Int24(4), new Int24(-400), new Int24(3222), new Int24(0), new Int24(25) }; Assert.AreEqual(25, array[0].Value); Assert.AreEqual(4, array[1].Value); Assert.AreEqual(-400, array[2].Value); Assert.AreEqual(3222, array[3].Value); Assert.AreEqual(0, array[4].Value); Assert.AreEqual(25, array[5].Value); Array.Sort(array); Assert.AreEqual(-400, array[0].Value); Assert.AreEqual(0, array[1].Value); Assert.AreEqual(4, array[2].Value); Assert.AreEqual(25, array[3].Value); Assert.AreEqual(25, array[4].Value); Assert.AreEqual(3222, array[5].Value); }
// Token: 0x0600050B RID: 1291 RVA: 0x000104B4 File Offset: 0x0000E6B4 public void WriteS24(Int24 value) { byte[] bytes = BitConverter.GetBytes(value); base.ResizeBuffer(3); Array.Copy(bytes, 0, base.Buffer, 0, 3); base.DumpBuffer(3); }
public void FailOnOverflow() { Int24 int24; bool parseResult = Int24.TryParse("8388608", NumberStyles.Integer, null, out int24); Assert.That(parseResult, Is.False); Assert.That(int24.Value, Is.EqualTo(0)); }
/// <summary> /// Returns a 24-bit signed integer converted from three bytes, accounting for target endian-order, at a specified position in a byte array. /// </summary> /// <param name="value">An array of bytes (i.e., buffer containing binary image of value).</param> /// <param name="startIndex">The starting position within value.</param> /// <returns>A 24-bit signed integer formed by three bytes beginning at startIndex.</returns> /// <exception cref="ArgumentNullException">value is null.</exception> /// <exception cref="ArgumentOutOfRangeException">startIndex is less than zero or greater than the length of value minus 1.</exception> public Int24 ToInt24(byte[] value, int startIndex) { byte[] buffer = new byte[3]; m_copyBuffer(value, startIndex, buffer, 0, 3); return(Int24.GetValue(buffer, 0)); }
public void Usage() { Int24 int24 = new Int24 { Value = 255 }; Assert.That(int24.Value, Is.EqualTo(255)); }
public static void TestOutOfRange(Int32 value) { TestHelpers.CatchUnexpected(() => { Assert.Throws <ArgumentOutOfRangeException>(() => { Int24 val = Int24.GetNew(value); }); }); }
public void FailOnWrongFormat() { Int24 int24; bool parseResult = Int24.TryParse("WILL FAIL", NumberStyles.None, null, out int24); Assert.That(parseResult, Is.False); Assert.That(int24.Value, Is.EqualTo(0)); }
public void Usage() { Int24 int24; bool parseResult = Int24.TryParse("255", NumberStyles.Integer, null, out int24); Assert.That(parseResult, Is.True); Assert.That(int24.Value, Is.EqualTo(255)); }
public static void TestValidValuesFromBytes(Int32 value) { TestHelpers.CatchUnexpected(() => { byte[] buffer = Int24.GetBytes(value); int pos = 0; Int24 val = Int24.GetNew(buffer, ref pos); Assert.AreEqual(value, val.Value, string.Format("On Set with Int32:{0}", buffer.ToHexByteString())); }); }
/// <summary> /// Generates a cryptographically strong 24-bit random integer between specified values. i.e. [<paramref name="startNumber"/>-<paramref name="stopNumber"/>) /// </summary> /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> /// <param name="startNumber">A <see cref="Int24"/> that is the low end of our range.</param> /// <param name="stopNumber">A <see cref="Int24"/> that is the high end of our range.</param> /// <returns>A <see cref="Int24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> public static Int24 Int24Between(Int24 startNumber, Int24 stopNumber) { if (stopNumber < startNumber) { throw new ArgumentException("stopNumber must be greater than startNumber"); } return((Int24)(GetRandomNumberLessThan((int)stopNumber - (int)startNumber) + (int)startNumber)); }
/// <summary> /// Generates a cryptographically strong 24-bit random integer between specified values. /// </summary> /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> /// <param name="startNumber">A <see cref="Int24"/> that is the low end of our range.</param> /// <param name="stopNumber">A <see cref="Int24"/> that is the high end of our range.</param> /// <returns>A <see cref="Int24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> public static Int24 Int24Between(Int24 startNumber, Int24 stopNumber) { if (stopNumber < startNumber) { throw new ArgumentException("stopNumber must be greater than startNumber"); } return((Int24)(Number * (stopNumber - startNumber) + startNumber)); }
private void EnqueueAck(IPEndPoint senderEndpoint, Int24 sequenceNumber) { _numberOfAckSent++; if (_playerSessions.ContainsKey(senderEndpoint)) { var session = _playerSessions[senderEndpoint]; session.PlayerAckQueue.Enqueue(sequenceNumber.IntValue()); } }
public void Reset() { IsAck = false; IsNak = false; IsPacketPair = false; HasBAndAs = false; IsContinuousSend = false; NeedsBAndAs = false; IsValid = false; DatagramSequenceNumber = 0; }
public void WillThrowArgumentException() { Int24 int24 = new Int24(); OverflowException exception = Assert.Throws <OverflowException>(() => int24.Value = 8388608); Assert.That(exception.Message, Is.EqualTo("Value was either too large or too small for an Int24.")); exception = Assert.Throws <OverflowException>(() => int24.Value = -8388609); Assert.That(exception.Message, Is.EqualTo("Value was either too large or too small for an Int24.")); }
public void Reset() { isACK = false; isNAK = false; isPacketPair = false; hasBAndAS = false; isContinuousSend = false; needsBAndAs = false; isValid = false; datagramSequenceNumber = 0; }
public void Usage() { Int24 int24 = new Int24 { Value = 32647 }; byte[] byteArray = int24.ToByteArray(); Assert.That(byteArray[0], Is.EqualTo(135)); Assert.That(byteArray[1], Is.EqualTo(127)); Assert.That(byteArray[2], Is.EqualTo(0)); }
public void Usage() { UInt24 int24 = new UInt24(10); Assert.That(int24.Value, Is.EqualTo(10)); Int24 secInt24 = new Int24(); Assert.That(secInt24.Value, Is.EqualTo(0)); secInt24.Value = 5; Assert.That(secInt24.Value, Is.EqualTo(5)); }
protected override void DecodePackage() { base.DecodePackage(); count = ReadShort(); onlyOneSequence = ReadByte(); sequenceNumber = ReadLittle(); if (onlyOneSequence == 0) { toSequenceNumber = ReadLittle(); } }
/// <summary> /// Attempts to convert a radix value to an integer value. /// </summary> /// <param name="radixValue">Radix value to convert.</param> /// <param name="value">Decoded integer value.</param> /// <returns><c>true</c> if decode succeeds; otherwise, <c>false</c>.</returns> public bool TryDecode(string radixValue, out Int24 value) { try { value = m_int24.Decode(radixValue); return(true); } catch { value = 0; return(false); } }
private void SendAck(IPEndPoint senderEndpoint, Int24 sequenceNumber) { var ack = new Ack { sequenceNumber = sequenceNumber, count = 1, onlyOneSequence = 1 }; var data = ack.Encode(); SendData(data); }
public void Acknowledge(Int24 datagramSequenceNumber) { var integerValue = datagramSequenceNumber.IntValue(); var last = Interlocked.Exchange(ref _lastDatagramSequenceNumber, integerValue); var skipped = last - integerValue - 1; if (skipped > 0) { for (long i = last + 1; i < integerValue - 1; i++) { OutgoingNackQueue.Enqueue((int)i); } } OutgoingAckQueue.Enqueue(datagramSequenceNumber); }
/// <summary> /// Reads the audio to the specified buffer. /// </summary> /// <param name="buffer">The buffer.</param> /// <returns> /// The length of the data written. /// </returns> public override int Read(Span <byte> buffer) { var cursor = MemoryMarshal.Cast <byte, Int24>(buffer); while (cursor.Length > 0) { var reader = cursor.Length >= readBuffer.Length ? readBuffer : readBuffer.Slice(0, cursor.Length); int u = Source.Read(reader.Span); var wrote = reader.Span.Slice(0, u); var dest = cursor.Slice(0, wrote.Length); if (wrote.Length != dest.Length) { new InvalidOperationException( $"The {nameof(wrote)}'s length and {nameof(dest)}'s length are not equal! This is a bug!").Throw(); } if (AccuracyMode) { var dsmAcc = dsmAccumulator.Span; var dsmLastOut = dsmLastOutput.Span; dsmChannelPointer %= dsmAcc.Length; for (int i = 0; i < dest.Length; i++) { var diff = wrote[i] - (dsmLastOut[dsmChannelPointer] / multiplier); dsmAcc[dsmChannelPointer] += diff; var v = dsmLastOut[dsmChannelPointer] = Convert(dsmAcc[dsmChannelPointer]); dest[i] = IsEndiannessConversionRequired ? Int24.ReverseEndianness(v) : v; dsmChannelPointer = ++dsmChannelPointer % dsmAcc.Length; } } else { for (int i = 0; i < dest.Length; i++) { var v = Convert(wrote[i]); dest[i] = IsEndiannessConversionRequired ? Int24.ReverseEndianness(v) : v; } } cursor = cursor.Slice(dest.Length); if (u != reader.Length) { return(buffer.Length - cursor.Length); //The Source doesn't fill whole reader so return here. } } return(buffer.Length); }
public override byte[] Write() { var buffer = new byte[256]; var offset = 0; foreach (var _byte in BitConverter.GetBytes(Convert.ToInt16(this.RoleId))) { buffer[offset] = _byte; offset += 1; } var RoleNameBytes = StringEncoding.GetBytes(this.RoleName); buffer[offset] = (byte)RoleNameBytes.Length; offset += 1; foreach (var _byte in RoleNameBytes) { buffer[offset] = _byte; offset += 1; } var IdBytes = Int24.GetBytes(this.Id); foreach (var _byte in IdBytes) { buffer[offset] = _byte; offset += 1; } var countIds = this.Ids == null ? 0 : this.Ids.Count; buffer[offset] = (byte)countIds; offset++; if (countIds > 0) { foreach (var item in this.Ids) { foreach (var _byte in Int24.GetBytes(item)) { buffer[offset] = _byte; offset++; } } } return(new ArraySegment <byte>(buffer, 0, offset).ToArray()); }
public void Should_SerializeInt24() { Int24 value = Int24.MaxValue; // range -8,388,607 to 8,388,607 Assert.AreEqual(false, value._sign); Assert.AreEqual(new byte[] { 255, 255, 127 }, value.GetBytes()); Assert.AreEqual(new Bit[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, value.GetBits()); value = Int24.MinValue; Assert.AreEqual(true, value._sign); Assert.AreEqual(new byte[] { 255, 255, 255 }, value.GetBytes()); Assert.AreEqual(new Bit[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, value.GetBits()); // test overflow value = (Int24)9000000; Assert.AreEqual(611392, value); Assert.AreEqual(false, value._sign); Assert.AreEqual(new byte[] { 64, 84, 9 }, value.GetBytes()); Assert.AreEqual(new Bit[] { 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0 }, value.GetBits()); }
public void TestCDF53ReversibilityInt24() { Int24[] array = new Int24[2048]; for (int i = 0; i < array.Length; i++) { array[i] = (Int24)(Int24.MaxValue * Math.Sin(2.0 * Math.PI * i / array.Length)); } Int24[] copy = new Int24[array.Length]; Array.Copy(array, copy, array.Length); Span <Int24> span = new Span <Int24>(array); WaveletTransformation.CDF53MultiLevel(span); Span <Int24> transformed = stackalloc Int24[array.Length]; span.CopyTo(transformed); WaveletTransformation.CDF53InverseMultiLevel(span); AssertEqualityAndDumpInt(array, copy, transformed); }
/// <summary> /// Reads the audio to the specified buffer. /// </summary> /// <param name="buffer">The buffer.</param> /// <returns> /// The length of the data written. /// </returns> public override int Read(Span <float> buffer) { Span <Int24> span = stackalloc Int24[buffer.Length > ActualBufferMax ? ActualBufferMax : buffer.Length]; var cursor = buffer; while (cursor.Length > 0) { var reader = cursor.Length >= span.Length ? span : span.Slice(0, cursor.Length); int u = Source.Read(MemoryMarshal.AsBytes(span)) / bytesPerSample; var wrote = reader.Slice(0, u); var dest = cursor.Slice(0, wrote.Length); if (wrote.Length != dest.Length) { new InvalidOperationException( $"The {nameof(wrote)}'s length and {nameof(dest)}'s length are not equal! This is a bug!").Throw(); } if (IsEndiannessConversionRequired) { for (int i = 0; i < wrote.Length && i < dest.Length; i++) { dest[i] = Int24.ReverseEndianness(wrote[i]) / divisor; } } else { for (int i = 0; i < wrote.Length && i < dest.Length; i++) { dest[i] = wrote[i] / divisor; } } cursor = cursor.Slice(u); if (u != reader.Length) { return(buffer.Length - cursor.Length); //The Source doesn't fill whole reader so return here. } } return(buffer.Length); }
/// <summary> /// Determines if specified <paramref name="bits"/> are set. /// </summary> /// <param name="source">Value source.</param> /// <param name="bits">Bit-mask of the bits to check.</param> /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> public static bool CheckBits(this Int24 source, Int24 bits) { return CheckBits(source, bits, true); }
/// <summary> /// Returns a simple encoded string representing a number which can later be decoded with <see cref="GetSeedFromKey"/>. /// </summary> /// <remarks>This function was designed for 24-bit values.</remarks> public static string GetKeyFromSeed(Int24 seed) { if (seed < 0) throw new ArgumentException("Cannot calculate key from negative seed"); // This is a handy algorithm for encoding an integer value, use GetSeedFromKey to decode. byte[] seedBytes = seed.GetBytes(); int alphaIndex; int asciiA = (int)'A'; // Creates alpha-numeric key string. StringBuilder result = new StringBuilder(); for (int x = 0; x < 3; x++) { alphaIndex = Random.Int32Between(0, 25); if (x > 0) result.Append('-'); result.Append((char)(asciiA + (25 - alphaIndex))); result.Append(seedBytes[x] + alphaIndex); } return result.ToString(); }
/// <summary>Performs proper bitwise conversion between signed and unsigned value</summary> /// <remarks> /// <para>This function is useful because CType(n, UInt24) will throw an OverflowException for values less than zero.</para> /// <para>For example, this function correctly converts signed 24-bit integer -8388608 (i.e., Int24.MinValue) to unsigned 24-bit integer 8388608.</para> /// </remarks> /// <param name="signedInt">Signed integer that is passed in to be converted to an unsigned integer.</param> /// <returns>The unsigned integer value.</returns> public static UInt24 ToUInt24(Int24 signedInt) { return UInt24.GetValue(Int24.GetBytes(signedInt), 0); }
public static void GetSamplesInt24(GThread thread, Int24[] samples, float[,] output) { var channels = output.GetLength(0); var sampleCount = output.GetLength(1); const float mid = -int24.MinValue; const float min = -int24.MaxValue; int tid = thread.blockIdx.x; while (tid < sampleCount) { for (int i = 0; i < channels; i++) { var index = (tid * channels) + i; var b0 = samples[index].B0; var b1 = samples[index].B1; var b2 = samples[index].B2; var v = b0 | (b1 << 8) | (b2 << 16); if ((v & 0x800000) != 0) { v |= ~0xffffff; } output[i, tid] = ((v - min) / mid) - 1.0f; } tid += thread.gridDim.x; } }
public static void PutSamplesInt24(GThread thread, float[,] samples, Int24[] output) { var channels = samples.GetLength(0); var sampleCount = samples.GetLength(1); const float mid = -int24.MinValue; const float min = -int24.MaxValue; int tid = thread.blockIdx.x; while (tid < sampleCount) { for (int i = 0; i < channels; i++) { var f = Clip(samples[i, tid]); var val = (int)((f + 1.0f) * mid + min); var index = (tid * channels) + i; output[index].B0 = (byte)(val & 0xFF); output[index].B1 = (byte)(val >> 8); output[index].B2 = (byte)(val >> 16); } tid += thread.gridDim.x; } }
/// <summary> /// Returns value with specified <paramref name="bits"/> toggled. /// </summary> /// <param name="source">Value source.</param> /// <param name="bits">Bit-mask of the bits to toggle.</param> /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> toggled.</returns> public static Int24 ToggleBits(this Int24 source, Int24 bits) { return (source ^ bits); }
/// <summary>Returns a simple encoded string representing a number which can later be decoded /// with <see cref="GetSeedFromKey" />.</summary> /// <remarks>This function was designed for 24-bit values.</remarks> public static string GetKeyFromSeed(Int24 seed) { if (seed < 0) throw new ArgumentException("Cannot calculate key from negative seed"); // This is a handy algorithm for encoding an integer value, use GetSeedFromKey to decode. int seedValue = (int)seed; byte[] seedBytes = new byte[4]; int alphaIndex; int asciiA = Strings.Asc('A'); // Breaks seed into its component bytes. seedBytes[0] = Bit.LoByte(Bit.LoWord(seedValue)); seedBytes[1] = Bit.HiByte(Bit.LoWord(seedValue)); seedBytes[2] = Bit.LoByte(Bit.HiWord(seedValue)); // Creates alpha-numeric key string. StringBuilder result = new StringBuilder(); for (int x = 0; x <= 2; x++) { alphaIndex = Random.Int32Between(0, 25); if (x > 0) result.Append('-'); result.Append(Convert.ToChar(asciiA + (25 - alphaIndex))); result.Append(seedBytes[x] + alphaIndex); } return result.ToString(); }
/// <summary> /// Generates a cryptographically strong 24-bit random integer between specified values. i.e. [<paramref name="startNumber"/>-<paramref name="stopNumber"/>) /// </summary> /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> /// <param name="startNumber">A <see cref="Int24"/> that is the low end of our range.</param> /// <param name="stopNumber">A <see cref="Int24"/> that is the high end of our range.</param> /// <returns>A <see cref="Int24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> public static Int24 Int24Between(Int24 startNumber, Int24 stopNumber) { if (stopNumber < startNumber) throw new ArgumentException("stopNumber must be greater than startNumber"); return (Int24)(GetRandomNumberLessThan((int)stopNumber - (int)startNumber) + (int)startNumber); }
/// <summary> /// Returns value stored in the bits represented by the specified <paramref name="bitmask"/>. /// </summary> /// <param name="source">Value source.</param> /// <param name="bitmask">Bit-mask of the bits involved.</param> /// <returns><see cref="Int24"/> value.</returns> public static Int24 GetMaskedValue(this Int24 source, Int24 bitmask) { return (source & bitmask); }
public static Int24 SetMaskedValue(this Int24 source, Bits bitmask, Int24 value) { checked { return SetMaskedValue(source, (Int24)bitmask, value); } }
/// <summary> /// Generates a cryptographically strong 24-bit random integer between specified values. /// </summary> /// <exception cref="System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.</exception> /// <param name="startNumber">A <see cref="Int24"/> that is the low end of our range.</param> /// <param name="stopNumber">A <see cref="Int24"/> that is the high end of our range.</param> /// <returns>A <see cref="Int24"/> that is generated between the <paramref name="startNumber"/> and the <paramref name="stopNumber"/>.</returns> public static Int24 Int24Between(Int24 startNumber, Int24 stopNumber) { if (stopNumber < startNumber) throw new ArgumentException("stopNumber must be greater than startNumber"); return (Int24)(Number * (stopNumber - startNumber) + startNumber); }
/// <summary> /// Copies the specified 24-bit signed integer value as an array of 3 bytes in the target endian-order to the destination array. /// </summary> /// <param name="value">The number to convert and copy.</param> /// <param name="destinationArray">The destination buffer.</param> /// <param name="destinationIndex">The byte offset into <paramref name="destinationArray"/>.</param> public void CopyBytes(Int24 value, byte[] destinationArray, int destinationIndex) { m_copyBuffer(Int24.GetBytes(value), 0, destinationArray, destinationIndex, 3); }
/// <summary> /// Returns the specified 24-bit signed integer value as an array of bytes. /// </summary> /// <param name="value">The number to convert.</param> /// <returns>An array of bytes with length 3.</returns> public byte[] GetBytes(Int24 value) { return m_coerceByteOrder(Int24.GetBytes(value)); }
/// <summary> /// Returns value after setting a new <paramref name="value"/> for the bits specified by the <paramref name="bitmask"/>. /// </summary> /// <param name="source">Value source.</param> /// <param name="bitmask">Bit-mask of the bits involved.</param> /// <param name="value">New value.</param> /// <returns><see cref="Int24"/> value.</returns> public static Int24 SetMaskedValue(this Int24 source, Int24 bitmask, Int24 value) { return ((source & ~bitmask) | value); }
/// <summary> /// Returns value with specified <paramref name="bits"/> set. /// </summary> /// <param name="source">Value source.</param> /// <param name="bits">Bit-mask of the bits to set.</param> /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> set.</returns> public static Int24 SetBits(this Int24 source, Int24 bits) { return (source | bits); }
/// <summary> /// Returns value with specified <paramref name="bits"/> cleared. /// </summary> /// <param name="source">Value source.</param> /// <param name="bits">Bit-mask of the bits to clear.</param> /// <returns><see cref="Int24"/> value with specified <paramref name="bits"/> cleared.</returns> public static Int24 ClearBits(this Int24 source, Int24 bits) { return (source & ~bits); }
/// <summary> /// Determines if specified <paramref name="bits"/> are set. /// </summary> /// <param name="source">Value source.</param> /// <param name="bits">Bit-mask of the bits to check.</param> /// <param name="allBits">true to check if all <paramref name="bits"/> are set; otherwise false.</param> /// <returns>true if specified <paramref name="bits"/> are set in <paramref name="source"/> value; otherwise false.</returns> public static bool CheckBits(this Int24 source, Int24 bits, bool allBits) { return (allBits ? ((source & bits) == bits) : ((source & bits) != 0)); }
/// <summary> /// Write a 24bit value based on the current stream and bit position /// </summary> public void WriteInt24(Int24 value) { WriteBytes(BitConverter.GetBytes(value), 24); }