32 lines
659 B
C#
32 lines
659 B
C#
namespace Common.Hardware.Interfaces.Protocols.SIRT.Messages.Parameters
|
|
{
|
|
using System;
|
|
|
|
public static class ByteExtensions
|
|
{
|
|
public static Byte[] GetBits(this Byte @byte)
|
|
{
|
|
var bits = new Byte[8];
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
bits[i] = (Byte)((@byte >> i) & 1);
|
|
}
|
|
|
|
return bits;
|
|
}
|
|
|
|
public static Byte GetByte(this Byte[] bits)
|
|
{
|
|
var @byte = default(int);
|
|
|
|
for (int i = 0; i < 8; i++)
|
|
{
|
|
@byte |= bits[i] << i;
|
|
}
|
|
|
|
return (Byte)@byte;
|
|
}
|
|
}
|
|
}
|