System.Convert.ToByte(uint)

Here are the examples of the csharp api System.Convert.ToByte(uint) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

19 Examples 7

19 Source : TextureCache.cs
with GNU General Public License v3.0
from ACEmulator

private static byte[] IndexToColor(ACE.DatLoader.FileTypes.Texture texture, bool isClipMap = false)
        {
            var colors = GetColors(texture);
            
            var palette = DatManager.PortalDat.ReadFromDat<Palette>((uint)texture.DefaultPaletteId);

            // Make a copy of the Palette Colors, so we don't inadvertently save them back to the dat File Cache
            List<uint> paletteColors = palette.Colors.ToList();

            // Apply any custom palette colors, if any, to our loaded palette (note, this may be all of them!)
            if (texture.CustomPaletteColors.Count > 0)
                foreach (var entry in texture.CustomPaletteColors)
                    if (entry.Key <= paletteColors.Count)
                        paletteColors[entry.Key] = entry.Value;

            var output = new byte[texture.Width * texture.Height * 4];

            for (int i = 0; i < texture.Height; i++)
            {
                for (int j = 0; j < texture.Width; j++)
                {
                    int idx = (i * texture.Width) + j;
                    var color = colors[idx];
                    var paletteColor = paletteColors[color];

                    byte a = Convert.ToByte((paletteColor & 0xFF000000) >> 24);
                    byte r = Convert.ToByte((paletteColor & 0xFF0000) >> 16);
                    byte g = Convert.ToByte((paletteColor & 0xFF00) >> 8);
                    byte b = Convert.ToByte(paletteColor & 0xFF);

                    if (isClipMap && color < 8)
                        r = g = b = a = 0;

                    output[idx * 4] = r;
                    output[idx * 4 + 1] = g;
                    output[idx * 4 + 2] = b;
                    output[idx * 4 + 3] = a;
                }
            }
            return output;
        }

19 Source : RIPEMD160Managed.cs
with GNU Affero General Public License v3.0
from blockbasenetwork

protected override byte[] HashFinal()
        {
            MDfinish(ref MDbuf, UnhashedBuffer, 0, Convert.ToUInt32(HashedLength), 0);

            var result = new byte[RMDsize / 8];

            for (var i = 0; i < RMDsize / 8; i += 4)
            {
                result[i] = Convert.ToByte(MDbuf[i >> 2] & 0xFF);         /* implicit cast to byte  */
                result[i + 1] = Convert.ToByte((MDbuf[i >> 2] >> 8) & 0xFF);  /*  extracts the 8 least  */
                result[i + 2] = Convert.ToByte((MDbuf[i >> 2] >> 16) & 0xFF);  /*  significant bits.     */
                result[i + 3] = Convert.ToByte((MDbuf[i >> 2] >> 24) & 0xFF);
            }

            return result;
        }

19 Source : PdfUInteger.cs
with MIT License
from damienbod

public byte ToByte(IFormatProvider provider)
        {
            return Convert.ToByte(_value);
        }

19 Source : utils.cs
with GNU General Public License v3.0
from dd-bim

public static Guid FromIfcGuid(string guid)
        {
            Debug.replacedert(guid.Length == 22, "Input string must not be longer that 22 chars");
            var num = new uint[6];
            char[] str = guid.ToCharArray();
            int n = 2, pos = 0, i;
            for (i = 0; i < 6; i++)
            {
                num[i] = CvFrom64(str, pos, n);
                pos += n;
                n = 4;
            }

            var a = (int)((num[0] * 16777216) + num[1]);
            var b = (short)(num[2] / 256);
            var c = (short)(((num[2] % 256) * 256) + (num[3] / 65536));
            var d = new byte[8];
            d[0] = Convert.ToByte((num[3] / 256) % 256);
            d[1] = Convert.ToByte(num[3] % 256);
            d[2] = Convert.ToByte(num[4] / 65536);
            d[3] = Convert.ToByte((num[4] / 256) % 256);
            d[4] = Convert.ToByte(num[4] % 256);
            d[5] = Convert.ToByte(num[5] / 65536);
            d[6] = Convert.ToByte((num[5] / 256) % 256);
            d[7] = Convert.ToByte(num[5] % 256);

            return new Guid(a, b, c, d);
        }

19 Source : BasicConvert.Overload.cs
with MIT License
from Dogwei

byte IXConverter<uint, byte>.Convert(uint value)
			=> Convert.ToByte(value);

19 Source : Utils.cs
with BSD 3-Clause "New" or "Revised" License
from EvolutionJobs

public static byte BitmaskToByte(uint value, uint mask)
        {
            value = value & mask;
            while ((mask & 0x1) != 0x1)
            {
                value = value >> 1;
                mask = mask >> 1;
            }
            return Convert.ToByte(value);
        }

19 Source : BytesHandler.cs
with GNU General Public License v3.0
from Glazelf

public static void WriteUInt(uint input, ulong offset, ISwitchConnectionSync sb)
        {
            byte value = Convert.ToByte(input);
            byte[] byteArray = new byte[1];
            byteArray[0] = value;
            sb.WriteBytesAbsolute(byteArray, offset);
            return;
        }

19 Source : IFCGuid.cs
with MIT License
from hypar-io

public static Guid FromIfcGUID( string guid )
    {
      Debug.replacedert( guid.Length == 22, "Input string must not be longer that 22 chars" );
      uint[] num = new uint[6];
      char[] str = guid.ToCharArray();
      int n = 2, pos = 0, i;
      for( i = 0; i < 6; i++ )
      {
        num[i] = cv_from_64( str, pos, n );
        pos += n; n = 4;
      }

      int a = ( int ) ( ( num[0] * 16777216 + num[1] ) );
      short b = ( short ) ( num[2] / 256 );
      short c = ( short ) ( ( num[2] % 256 ) * 256 + num[3] / 65536 );
      byte[] d = new byte[8];
      d[0] = Convert.ToByte( ( num[3] / 256 ) % 256 );
      d[1] = Convert.ToByte( num[3] % 256 );
      d[2] = Convert.ToByte( num[4] / 65536 );
      d[3] = Convert.ToByte( ( num[4] / 256 ) % 256 );
      d[4] = Convert.ToByte( num[4] % 256 );
      d[5] = Convert.ToByte( num[5] / 65536 );
      d[6] = Convert.ToByte( ( num[5] / 256 ) % 256 );
      d[7] = Convert.ToByte( num[5] % 256 );

      return new Guid( a, b, c, d );
    }

19 Source : DataExtraction.cs
with MIT License
from mahalex

private static byte[] UintToByte(uint[] source)
        {
            var result = new byte[source.Length];
            for (var i = 0; i < source.Length; i++)
            {
                result[i] = Convert.ToByte(source[i]);
            }

            return result;
        }

19 Source : ColorPickerHelper.cs
with MIT License
from mameolan

internal static Color MakeColorFromRGB(uint alpha, uint red, uint green, uint blue)
        {
            byte abyteValue = Convert.ToByte(alpha);
            byte rbyteValue = Convert.ToByte(red);
            byte gbyteValue = Convert.ToByte(green);
            byte bbyteValue = Convert.ToByte(blue);
            Color rgbColor =
                 Color.FromArgb(
                     abyteValue,
                     rbyteValue,
                     gbyteValue,
                     bbyteValue);
            return rgbColor;
        }

19 Source : frmDataCheck.cs
with GNU General Public License v2.0
from mcuxmx

private string getStringByUint32(UInt32 value, bool IsMSBFirst, int dataWidth)
        {
            byte[] array = new byte[4];

            array[0] = Convert.ToByte((value >> 24) & 0xFF);
            array[1] = Convert.ToByte((value >> 16) & 0xFF);
            array[2] = Convert.ToByte((value >> 8) & 0xFF);
            array[3] = Convert.ToByte((value >> 0) & 0xFF);

            StringBuilder sb = new StringBuilder();
            if (IsMSBFirst)
            {
                switch (dataWidth)
                {
                    case 8:
                        sb.AppendFormat("{0:X2}", array[3]);
                        break;
                    case 16:
                        sb.AppendFormat("{0:X2}", array[2]);
                        sb.AppendFormat("{0:X2}", array[3]);
                        break;
                    case 32:
                        sb.AppendFormat("{0:X2}", array[0]);
                        sb.AppendFormat("{0:X2}", array[1]);
                        sb.AppendFormat("{0:X2}", array[2]);
                        sb.AppendFormat("{0:X2}", array[3]);
                        break;
                }
            }
            else
            {
                switch (dataWidth)
                {
                    case 8:
                        sb.AppendFormat("{0:X2}", array[3]);
                        break;
                    case 16:
                        sb.AppendFormat("{0:X2}", array[3]);
                        sb.AppendFormat("{0:X2}", array[2]);

                        break;
                    case 32:
                        sb.AppendFormat("{0:X2}", array[3]);
                        sb.AppendFormat("{0:X2}", array[2]);
                        sb.AppendFormat("{0:X2}", array[1]);
                        sb.AppendFormat("{0:X2}", array[0]);
                        break;
                }
            }

            return sb.ToString();
        }

19 Source : UInt32Extensions.cs
with GNU General Public License v3.0
from ME3Tweaks

public static byte ToByte(this uint value)
		{
			return Convert.ToByte(value);
		}

19 Source : Filter.cs
with GNU Affero General Public License v3.0
from SapphireServer

public bool IsApplicableForFilterSet(PacketEntry item)
        {
            try
            {
                switch (this.type)
                {
                    case FilterType.Message:
                    {
                        var valStr = (string)value;
                        string[] split;
                        NumberStyles styles = NumberStyles.Any;

                        if ((split = valStr.Split('x')).Length > 1)
                        {
                            valStr = split[1];
                            styles = NumberStyles.HexNumber;
                        }
                        else if ((split = valStr.Split('X')).Length > 1)
                        {
                            valStr = split[1];
                            styles = NumberStyles.HexNumber;
                        }
                        
                        if (UInt16.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findUInt16))
                        {
                            for (var i = 0; i + sizeof(UInt16) - 1 < item.Data.Length; ++i)
                            {
                                return item.Message == findUInt16.ToString("X4");
                            }
                        }
                    }
                    break;

                    case FilterType.ActorControl:
                    {
                        var valStr = (string)value;
                        string[] split;
                        NumberStyles styles = NumberStyles.Any;

                        if ((split = valStr.Split('x')).Length > 1)
                        {
                            valStr = split[1];
                            styles = NumberStyles.HexNumber;
                        }
                        else if ((split = valStr.Split('X')).Length > 1)
                        {
                            valStr = split[1];
                            styles = NumberStyles.HexNumber;
                        }
                        
                        if (UInt16.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findUInt16))
                        {
                            for (var i = 0; i + sizeof(UInt16) - 1 < item.Data.Length; ++i)
                            {
                                return item.ActorControl == findUInt16;
                            }
                        }
                    }
                    break;

                    case FilterType.ActorControlName:
                        if (item.ActorControl != -1 && item.Name.ToLower().Contains(((string)this.value).ToLower()))
                        {
                            return true;
                        }
                        break;

                    case FilterType.PacketName:
                        if (item.Name.ToLower().Contains(((string)this.value).ToLower()))
                        {
                            return true;
                        }
                        break;

                    case FilterType.StringContents:
                        var findStr = Convert.ToString(this.value).ToLower();
                        var packetStr = Encoding.UTF8.GetString(item.Data).ToLower();

                        if (packetStr.Contains(findStr))
                        {
                            return true;
                        }
                        break;
                    // todo: these are horribly inefficient
                    case FilterType.Int64:
                        {
                            var valStr = (string)value;
                            string[] split;
                            NumberStyles styles = NumberStyles.Any;

                            if ((split = valStr.Split('x')).Length > 1)
                            {
                                valStr = split[1];
                                styles = NumberStyles.HexNumber;
                            }
                            else if ((split = valStr.Split('X')).Length > 1)
                            {
                                valStr = split[1];
                                styles = NumberStyles.HexNumber;
                            }

                            if (Int64.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findInt64))
                            {
                                for (var i = 0; i + sizeof(Int64) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToInt64(item.Data, i) == findInt64)
                                        return true;
                                }
                            }
                            if (UInt64.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findUInt64))
                            {
                                for (var i = 0; i + sizeof(UInt64) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToUInt64(item.Data, i) == findUInt64)
                                        return true;
                                }
                            }
                        }
                        break;
                    case FilterType.Int32:
                        {
                            var valStr = (string)value;
                            string[] split;
                            NumberStyles styles = NumberStyles.Any;

                            if ((split = valStr.Split('x')).Length > 1)
                            {
                                valStr = split[1];
                                styles = NumberStyles.HexNumber;
                            }
                            else if ((split = valStr.Split('X')).Length > 1)
                            {
                                valStr = split[1];
                                styles = NumberStyles.HexNumber;
                            }

                            if (Int32.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findInt32))
                            {
                                for (var i = 0; i + sizeof(Int32) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToInt32(item.Data, i) == findInt32)
                                        return true;
                                }
                            }
                            if (UInt32.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findUInt32))
                            {
                                for (var i = 0; i + sizeof(UInt32) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToUInt32(item.Data, i) == findUInt32)
                                        return true;
                                }
                            }
                        }
                        break;
                    case FilterType.Int16:
                        {
                            var valStr = (string)value;
                            string[] split;
                            NumberStyles styles = NumberStyles.Any;

                            if ((split = valStr.Split('x')).Length > 1)
                            {
                                valStr = split[1];
                                styles = NumberStyles.HexNumber;
                            }
                            else if ((split = valStr.Split('X')).Length > 1)
                            {
                                valStr = split[1];
                                styles = NumberStyles.HexNumber;
                            }

                            if (Int16.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findInt16))
                            {
                                for (var i = 0; i + sizeof(Int16) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToInt16(item.Data, i) == findInt16)
                                        return true;
                                }
                            }
                            if (UInt16.TryParse(valStr, styles, CultureInfo.CurrentCulture, out var findUInt16))
                            {
                                for (var i = 0; i + sizeof(UInt16) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToUInt16(item.Data, i) == findUInt16)
                                        return true;
                                }
                            }
                        }
                        break;
                    case FilterType.Int8:
                        {
                            var valStr = (string)value;
                            string[] split;
                            int convertBase = 10;
                            if ((split = valStr.Split('x')).Length > 1)
                            {
                                valStr = split[1];
                                convertBase = 16;
                            }
                            else if ((split = valStr.Split('X')).Length > 1)
                            {
                                valStr = split[1];
                                convertBase = 16;
                            }

                            var findInt8 = System.Convert.ToChar(System.Convert.ToUInt32(valStr, convertBase));
                            {
                                for (var i = 0; i < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToChar(item.Data, i) == findInt8)
                                        return true;
                                }
                            }

                            var findUInt8 = System.Convert.ToByte(System.Convert.ToUInt32(valStr, convertBase));
                            {
                                for (var i = 0; i < item.Data.Length; ++i)
                                {
                                    if (item.Data[i] == findUInt8)
                                        return true;
                                }
                            }
                        }
                        break;
                    case FilterType.Float:
                        {
                            if (float.TryParse((string)value, out var findFloat))
                            {
                                for (var i = 0; i + sizeof(float) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToSingle(item.Data, i) == findFloat)
                                        return true;
                                }
                            }
                        }
                        break;
                    case FilterType.Double:
                        {
                            if (double.TryParse((string)value, out var findDouble))
                            {
                                for (var i = 0; i + sizeof(double) - 1 < item.Data.Length; ++i)
                                {
                                    if (BitConverter.ToSingle(item.Data, i) == findDouble)
                                        return true;
                                }
                            }
                        }
                        break;
                    case FilterType.ByteArray:
                        {
                            string valStr = value.ToString().Replace(" ", "");
                            List<byte> findBytes = new List<byte>();

                            for (var i = 0; i + 1 < valStr.Length; i += 2)
                            {
                                findBytes.Add(Convert.ToByte(Convert.ToUInt32(valStr.Substring(i, 2), 16)));
                            }

                            for (var i = 0; i + findBytes.Count - 1 < item.Data.Length; ++i)
                            {
                                if (item.Data[i] == findBytes[0])
                                {
                                    bool isMatch = true;
                                    for (var j = 0; j < findBytes.Count; ++j)
                                    {
                                        if (item.Data[i + j] != findBytes[j])
                                        {
                                            isMatch = false;
                                            break;
                                        }
                                    }

                                    if (isMatch)
                                        return true;
                                }
                            }
                        }
                        break;
                    default:
                        break;
                }
            }
            catch (Exception e)
            {
                return false;
            }

            return false;
        }

19 Source : UIntConvertor.cs
with GNU General Public License v3.0
from SeeSharpOpenSource

protected override void InitializeConvertFuncs()
        {
            ConvertFuncs.Add(typeof(decimal).Name, sourceValue => System.Convert.ToDecimal((uint)sourceValue));
            ConvertFuncs.Add(typeof(double).Name, sourceValue => System.Convert.ToDouble((uint)sourceValue));
            ConvertFuncs.Add(typeof(float).Name, sourceValue => System.Convert.ToSingle((uint)sourceValue));
            ConvertFuncs.Add(typeof(long).Name, sourceValue => System.Convert.ToInt64((uint)sourceValue));
            ConvertFuncs.Add(typeof(ulong).Name, sourceValue => System.Convert.ToUInt64((uint)sourceValue));
            ConvertFuncs.Add(typeof(int).Name, sourceValue => System.Convert.ToInt32((uint)sourceValue));
//            ConvertFuncs.Add(typeof(uint).Name, sourceValue => System.Convert.ToUInt32((uint)sourceValue));
            ConvertFuncs.Add(typeof(short).Name, sourceValue => System.Convert.ToInt16((uint)sourceValue));
            ConvertFuncs.Add(typeof(ushort).Name, sourceValue => System.Convert.ToUInt16((uint)sourceValue));
            ConvertFuncs.Add(typeof(char).Name, sourceValue => System.Convert.ToChar((uint)sourceValue));
            ConvertFuncs.Add(typeof(byte).Name, sourceValue => System.Convert.ToByte((uint)sourceValue));
            ConvertFuncs.Add(typeof(bool).Name, sourceValue => (uint)sourceValue > 0);
            ConvertFuncs.Add(typeof(string).Name, sourceValue => sourceValue.ToString());
        }

19 Source : MemoryFile.cs
with GNU General Public License v3.0
from shibbo

public override void Write(uint val)
        {
            Expand(mPosition + 4);
            if (mIsBigEndian)
            {
                mBuffer[mPosition++] = Convert.ToByte((val >> 24) & 0xFF);
                mBuffer[mPosition++] = Convert.ToByte((val >> 16) & 0xFF);
                mBuffer[mPosition++] = Convert.ToByte((val >> 8) & 0xFF);
                mBuffer[mPosition++] = Convert.ToByte(val & 0xFF);
            }
            else
            {
                mBuffer[mPosition++] = Convert.ToByte(val & 0xFF);
                mBuffer[mPosition++] = Convert.ToByte((val >> 8) & 0xFF);
                mBuffer[mPosition++] = Convert.ToByte((val >> 16) & 0xFF);
                mBuffer[mPosition++] = Convert.ToByte((val >> 24) & 0xFF);
            }
        }

19 Source : UInt32.cs
with MIT License
from Team-RTCLI

byte IConvertible.ToByte(IFormatProvider? provider)
        {
            return Convert.ToByte(m_value);
        }

19 Source : FlashRuntimeExtensions.cs
with Apache License 2.0
from tuarua

public static Color AsColor(this FREObject freObject, bool hasAlpha = true) {
            var rgb = freObject.AsUInt();
            if (hasAlpha) {
                return Color.FromArgb(
                    Convert.ToByte((rgb >> 24) & 0xff),
                    Convert.ToByte((rgb >> 16) & 0xff),
                    Convert.ToByte((rgb >> 8) & 0xff),
                    Convert.ToByte(rgb & 0xff));
            }

            return Color.FromArgb(
                Convert.ToByte((rgb >> 16) & 0xff),
                Convert.ToByte((rgb >> 8) & 0xff),
                Convert.ToByte(rgb & 0xff));
        }

19 Source : StructFunctions.cs
with GNU General Public License v3.0
from WolvenKit

public static Vector4 TenBitsigned(UInt32 U32)
        {
            Int16 X = Convert.ToInt16(U32 & 0x3ff);
            Int16 Y = Convert.ToInt16((U32 >> 10) & 0x3ff);
            Int16 Z = Convert.ToInt16((U32 >> 20) & 0x3ff);
            byte W = Convert.ToByte((U32) >> 30);

            if (X > 511)
                X = (Int16)(-1 * (X - 512));
            if (Y > 511)
                Y = (Int16)(-1 * (Y - 512));
            if (Z > 511)
                Z = (Int16)(-1 * (Z - 512));
            return new Vector4(X / 512f, Y / 512f, Z / 512f, W / 3f);
        }

19 Source : Encoder.cs
with MIT License
from yimengfan

public static byte[] encodeUInt32(uint n)
        {
           
            //
            List<byte> byteList = new List<byte>();
            do
            {
                uint tmp  = n % 128;
                uint next = n >> 7;
                if (next != 0)
                {
                    tmp = tmp + 128;
                }
                byteList.Add(Convert.ToByte(tmp));
                n = next;
            } while (n != 0);

            return byteList.ToArray();
        }