public static int Encode_Bitstring(ref Byte[] apdu, ref BACNET_BIT_STRING bit_string, int pos)
        {
            int  len = 0;
            Byte remaining_used_bits = 0;
            Byte used_bytes          = 0;
            Byte i = 0;

            if (bit_string.bits_used == 0)
            {
                apdu[pos] = 0;
                len++;
            }
            else
            {
                used_bytes          = bit_string.bytes_used();
                remaining_used_bits = (Byte)(bit_string.bits_used - ((used_bytes -
                                                                      1) * 8));
                apdu[pos + len++] = (Byte)(8 - remaining_used_bits);
                for (i = 0; i < used_bytes; i++)
                {
                    apdu[pos + len++] = bit_string.byte_reverse_bits(bit_string.bitstring_octet(i));
                }
            }
            return(len);
        }
        public static int Decode_Bitstring(ref Byte[] apdu, UInt32 len_value, ref BACNET_BIT_STRING bit_string, int pos)
        {
            int    len         = 0;
            Byte   unused_bits = 0;
            UInt32 i           = 0;
            UInt32 bytes_used  = 0;

            //bitstring_init(bit_string);
            bytes_used = len_value - 1;
            for (i = 0; i < bytes_used; i++)
            {
                bit_string.set_octet((Byte)i, bit_string.byte_reverse_bits(apdu[pos + len++]));
            }
            unused_bits = (Byte)(apdu[pos] & 0x07);
            bit_string.set_bits_used((Byte)bytes_used, unused_bits);
            return(len);
        }