Beispiel #1
0
        public static BitRprArrayToStringResult BitRprArrayGetAsciiString(BitRprArrayToStringResult r, int count)
        {
            var oemArray = new List <byte>();

            for (var i = 0; i < count; i++)
            {
                r = BitUtil.BitRprArrayGet(r, 8);
                oemArray.Add(r.ValueAsByte);
            }
            r.StringValue = System.Text.Encoding.Default.GetString(oemArray.ToArray());
            return(r);
        }
Beispiel #2
0
        public static BitRprArrayToStringResult BitRprArrayGet(string bitArrayDef, int count, int shiftRight = 0, int bitCount = 0, bool autoRightShift8 = false)
        {
            if (autoRightShift8) // Auto compute how much we need to shift for an 8 bit value
            {
                shiftRight = 8 - count;
            }

            var r = new BitRprArrayToStringResult()
            {
                BitCount = bitCount
            };

            List <UInt32> powers = null;

            if (count > 24 && count <= 32)
            {
                powers = new List <UInt32>()
                {
                    2147483648, 1073741824, 536870912, 268435456, 134217728, 67108864, 33554432, 16777216,
                    8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536,
                    32768, 16384, 8192, 4096, 2048, 1024, 512, 256,
                    128, 64, 32, 16, 8, 4, 2, 1
                };
            }
            else if (count > 16 && count <= 24)
            {
                powers = new List <UInt32>()
                {
                    8388608, 4194304, 2097152, 1048576, 524288, 262144, 131072, 65536,
                    32768, 16384, 8192, 4096, 2048, 1024, 512, 256,
                    128, 64, 32, 16, 8, 4, 2, 1
                };
            }
            else if (count > 8 && count <= 16)
            {
                powers = new List <UInt32>()
                {
                    32768, 16384, 8192, 4096, 2048, 1024, 512, 256,
                    128, 64, 32, 16, 8, 4, 2, 1
                };
            }
            else if (count <= 8)
            {
                powers = new List <UInt32>()
                {
                    128, 64, 32, 16, 8, 4, 2, 1
                };
            }

            r.BitCount += count;
            var s  = bitArrayDef.Substring(0, count);
            var si = 0;

            if (powers.Count > 8)
            {
                si = powers.Count - s.Length;
            }

            for (var i = 0; i < s.Length; i++)
            {
                if (s[i] == '1')
                {
                    r.Value += powers[si];
                }
                si++;
            }
            r.BitArrayDef = bitArrayDef.Substring(count);

            if (shiftRight > 0)
            {
                r.Value = r.Value >> shiftRight;
            }
            return(r);
        }
Beispiel #3
0
 public static BitRprArrayToStringResult BitRprArrayGet(BitRprArrayToStringResult ba, int count, int shiftRight = 0, bool autoRightShift8 = false)
 {
     return(BitRprArrayGet(ba.BitArrayDef, count, shiftRight, ba.BitCount, autoRightShift8));
 }