zoukankan      html  css  js  c++  java
  • FieldOffset

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Globalization;
    using System.IO;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    namespace myFieldOffset
    {
        [StructLayout(LayoutKind.Explicit)]
        public struct DWORDIPAddress
        {
            [FieldOffset(0)]
            public uint Address;
            [FieldOffset(3)]
            public byte Byte1;
            [FieldOffset(2)]
            public byte Byte2;
            [FieldOffset(1)]
            public byte Byte3;
            [FieldOffset(0)]
            public byte Byte4;
        }
        class Program
        {
            //数据2291298690的二进制10001000--10010010--01110001--10000010
            static void Main(string[] args)
            {
                uint nIPAddress = 2291298690;
                DWORDIPAddress address = new DWORDIPAddress
                {
                    Address = nIPAddress
                };
                Console.WriteLine("{0}", address.Address);//10001000100100100111000110000010-->2291298690
                Console.WriteLine("{0}", address.Byte1);//10001000-->136
                Console.WriteLine("{0}", address.Byte2);//10010010-->146
                Console.WriteLine("{0}", address.Byte3);//01110001-->113
                Console.WriteLine("{0}", address.Byte4);//10000010-->130
                Console.ReadLine();
            }
        }
    }
     
  • 相关阅读:
    字典操作
    集合操作
    字符编码与转码
    基于Vue的WebApp项目开发(二)
    算法之递归
    webpack学习(一)
    基于Vue的WebApp项目开发(一)
    webpack踩坑之旅
    vue2.0中的watch和计算属性computed
    vue2.0路由写法、传参和嵌套
  • 原文地址:https://www.cnblogs.com/chucklu/p/3555700.html
Copyright © 2011-2022 走看看