struct MyStruct {
public byte F1;
public byte F2;
public byte F3;
public byte F4;

MyStruct s;
s.F1 = 0x00;
s.F2 = 0xF1;
s.F3 = 0x00;
s.F4 = 0x01;

uint p = 0x00F10001;

How can I convert MyStruct s to uint p ?
Thanks in advance.

I did try the following:
p = (uint) s;

But it didn't work.

Instead of writing my own function, does C# provide any function in doing this?
Any help/comment will be appreciate.

He sunny1106 go white your cellar or something.
wilsoncls, indeed my cast proposal did not work but this might help it is something to acces individual bits in an integer with an indexer.

struct IntBits
        private int _bits;

        public IntBits(int InitialBitValue)
            _bits = InitialBitValue;

        //declare indexer
        public bool this[int index]
                return (_bits & (1 << index)) != 0;
                if (value)
                    _bits |= (1 << index);  //set bit index 1
                    _bits &= ~(1 << index); //set bit index 0           

It is used like this
int a=12;
IntBits Mybits= new IntBits(a);

In this case Mybits[2] would be true, Mybits[1] would return false

This article has been dead for over six months. Start a new discussion instead.