Blaze.Server.Utils.SwapBytes C# (CSharp) Method

SwapBytes() public static method

public static SwapBytes ( uint word ) : uint
word uint
return uint
        public static uint SwapBytes(uint word)
        {
            // convert big endian to little endian
            return ((word >> 24) & 0x000000FF) | ((word >> 8) & 0x0000FF00) | ((word << 8) & 0x00FF0000) | ((word << 24) & 0xFF000000);
        }
    }

Usage Example

Beispiel #1
0
        /// <summary>
        /// Decodes a tag to a label.
        /// </summary>
        private string ReadLabel()
        {
            // by Pedro Martins
            string label = "";
            uint   tag   = 0;

            // get tag bytes
            byte[] tagBytes = new byte[3];
            _stream.Read(tagBytes, 0, 3);

            // resize tag byte array (add an empty byte)
            Array.Resize(ref tagBytes, 4);

            // read tag value (as uint32) from tag byte array
            tag = BitConverter.ToUInt32(tagBytes, 0);

            // convert to little endian
            tag = Utils.SwapBytes(tag) >> 8;

            // convert tag to label
            label += Convert.ToChar((((tag >> 18) & 0x3F) & 0x1F) | 64);
            label += Convert.ToChar((((tag >> 12) & 0x3F) & 0x1F) | 64);
            label += Convert.ToChar((((tag >> 6) & 0x3F) & 0x1F) | 64);
            label += Convert.ToChar(((tag & 0x3F) & 0x1F) | 64);

            // clean label
            label = Regex.Replace(label, "[^A-Z]+", "");

            return(label);
        }
All Usage Examples Of Blaze.Server.Utils::SwapBytes