Exemplo n.º 1
0
        private void PrivatePackCore(float value)
        {
            this.WriteByte(0xca);
            Float32Bits bits = new Float32Bits(value);

            if (BitConverter.IsLittleEndian)
            {
                this.WriteByte(bits.Byte3);
                this.WriteByte(bits.Byte2);
                this.WriteByte(bits.Byte1);
                this.WriteByte(bits.Byte0);
            }
            else
            {
                this.WriteByte(bits.Byte0);
                this.WriteByte(bits.Byte1);
                this.WriteByte(bits.Byte2);
                this.WriteByte(bits.Byte3);
            }
        }
Exemplo n.º 2
0
 public Float32Bits(byte[] bigEndianBytes, int offset)
 {
     Contract.Assume(bigEndianBytes != null);
     Contract.Assume((bigEndianBytes.Length - offset) >= 4, bigEndianBytes.Length.ToString() + "-" + offset.ToString() + ">= 4");
     this = new Float32Bits();
     if (BitConverter.IsLittleEndian)
     {
         this.Byte0 = bigEndianBytes[offset + 3];
         this.Byte1 = bigEndianBytes[offset + 2];
         this.Byte2 = bigEndianBytes[offset + 1];
         this.Byte3 = bigEndianBytes[offset];
     }
     else
     {
         this.Byte0 = bigEndianBytes[offset];
         this.Byte1 = bigEndianBytes[offset + 1];
         this.Byte2 = bigEndianBytes[offset + 2];
         this.Byte3 = bigEndianBytes[offset + 3];
     }
 }
Exemplo n.º 3
0
        private void PrivatePackCore(float value)
        {
            this.WriteByte(MessagePackCode.Real32);

            var bits = new Float32Bits(value);

            if (BitConverter.IsLittleEndian)
            {
                this.WriteByte(bits.Byte3);
                this.WriteByte(bits.Byte2);
                this.WriteByte(bits.Byte1);
                this.WriteByte(bits.Byte0);
            }
            else
            {
                this.WriteByte(bits.Byte0);
                this.WriteByte(bits.Byte1);
                this.WriteByte(bits.Byte2);
                this.WriteByte(bits.Byte3);
            }
        }
Exemplo n.º 4
0
        public static int ToBits(float value)
        {
            var bits   = new Float32Bits(value);
            var result = default(int);

            // Float32Bits usage is effectively pointer dereference operation rather than shifting operators, so we must consider endianness here.
            if (BitConverter.IsLittleEndian)
            {
                result  = bits.Byte3 << 24;
                result |= bits.Byte2 << 16;
                result |= bits.Byte1 << 8;
                result |= bits.Byte0;
            }
            else
            {
                result  = bits.Byte0 << 24;
                result |= bits.Byte1 << 16;
                result |= bits.Byte2 << 8;
                result |= bits.Byte3;
            }

            return(result);
        }
Exemplo n.º 5
0
 public Float32Bits(float value)
 {
     this       = new Float32Bits();
     this.Value = value;
 }