c#long bytes[]相互回転

5343 ワード

c#long bytes[]相互回転

        public static void SetBytes(this byte[] instance, int offset, long value)
        {
            Contract.Requires(instance != null);

            instance[offset++] = (byte)value;
            instance[offset++] = (byte)(value >> 8);
            instance[offset++] = (byte)(value >> 0x10);
            instance[offset++] = (byte)(value >> 0x18);
            instance[offset++] = (byte)(value >> 0x20);
            instance[offset++] = (byte)(value >> 40);
            instance[offset++] = (byte)(value >> 0x30);
            instance[offset] = (byte)(value >> 0x38);
        }

        public static long ToInt64(this byte[] instance, int offset)
        {
            Contract.Requires(instance != null);

            uint num = (uint)(((instance[offset++] | (instance[offset++] << 8)) | (instance[offset++] << 0x10)) | (instance[offset++] << 0x18));
            uint num2 = (uint)(((instance[offset++] | (instance[offset++] << 8)) | (instance[offset++] << 0x10)) | (instance[offset] << 0x18));
            return (long)((num2 << 0x20) | num);
        }

 
        public static void SetBytes(this byte[] instance, int offset, int value)
        {
            Contract.Requires(instance != null);

            instance[offset++] = (byte)(value);
            instance[offset++] = (byte)(value >> 8);
            instance[offset++] = (byte)(value >> 16);
            instance[offset] = (byte)(value >> 24);
        }

        public static int ToInt32(this byte[] instance, int offset)
        {
            Contract.Requires(instance != null);

            return (int)(instance[offset++] | instance[offset++] << 8 | instance[offset++] << 16 | instance[offset] << 24);
        }

 
posted on 2013-05-09 19:41 RockyLOMO読書(...)コメント(…)コレクションの編集