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()]
public uint Address;
[FieldOffset()]
public byte Byte1;
[FieldOffset()]
public byte Byte2;
[FieldOffset()]
public byte Byte3;
[FieldOffset()]
public byte Byte4;
}
class Program
{
//数据2291298690的二进制10001000--10010010--01110001--10000010
static void Main(string[] args)
{
uint nIPAddress = ;
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();
}
}
}