Googler

两情相悦,又岂在朝朝暮暮。

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  阅读(1755)  评论(0编辑  收藏  举报

导航

Apple/苹果笔记本 Mac Air MC968CH/A 行货在保 I5 11寸 超级本