Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Champs de bits

4 réponses
Avatar
ginoo
Bonjour à tous,

il existait avant en C ou C++ ce que l'on appelait les champs de bits


exemple
struct x
{
unsigned char Bit0 : 1;
unsigned char Bit1 : 1;
unsigned char Bit2 : 1;
unsigned char Bit3 : 1;
unsigned char Bit4 : 1;
unsigned char Bit5 : 1;
unsigned char Bit6 : 1;
unsigned char Bit7 : 1;
};

existe t-il un equivalent en c#

merci d'avance

4 réponses

Avatar
most
ginoo a écrit :
Bonjour à tous,

il existait avant en C ou C++ ce que l'on appelait les champs de bits


exemple
struct x
{
unsigned char Bit0 : 1;
unsigned char Bit1 : 1;
unsigned char Bit2 : 1;
unsigned char Bit3 : 1;
unsigned char Bit4 : 1;
unsigned char Bit5 : 1;
unsigned char Bit6 : 1;
unsigned char Bit7 : 1;
};

existe t-il un equivalent en c#

merci d'avance


On appelait peut être aussi structure de bits
Avatar
Delf
ginoo a écrit :

Bonjour à tous,



Bonjour

il existait avant en C ou C++ ce que l'on appelait les champs de bits


exemple
struct x
{
unsigned char Bit0 : 1;
unsigned char Bit1 : 1;
unsigned char Bit2 : 1;
unsigned char Bit3 : 1;
unsigned char Bit4 : 1;
unsigned char Bit5 : 1;
unsigned char Bit6 : 1;
unsigned char Bit7 : 1;
};

existe t-il un equivalent en c#



Cette structure représente un octet là non ?

byte[] octet = new byte[8]

--
Delf
Avatar
Gilles TOURREAU
Le Wed, 15 Aug 2007 16:03:48 +0200, ginoo a écrit:

Bonjour à tous,

il existait avant en C ou C++ ce que l'on appelait les champs de bits


exemple
struct x
{
unsigned char Bit0 : 1;
unsigned char Bit1 : 1;
unsigned char Bit2 : 1;
unsigned char Bit3 : 1;
unsigned char Bit4 : 1;
unsigned char Bit5 : 1;
unsigned char Bit6 : 1;
unsigned char Bit7 : 1;
};

existe t-il un equivalent en c#

merci d'avance



cf : System.Collections.Specialized.BitVector32

Cordialement

--
Gilles TOURREAU


S.A.R.L. P.O.S
Le spécialiste en motoculture depuis + de 30 ans !
http://www.pos.fr
Avatar
Jean BONBEUR
les unions et les champs de bits sont sans grand interet.
si c'est pour mapper une donnée sous-typée, jetter un oeil sur de l'interop.
si c'est à des fins plus "objet", l'implantation pourrait ressembler à ça


public sealed class X : object
{
private byte b = 0 ;

public bool Bit0
{
get
{
return b & 1 != 0 ;
}
set
{
if(value)
b = b | 1 ;
else
b = b & 254 ;
}
}

...
}



"ginoo" a écrit dans le message de news:
46c307c5$0$5083$
Bonjour à tous,

il existait avant en C ou C++ ce que l'on appelait les champs de bits


exemple
struct x
{
unsigned char Bit0 : 1;
unsigned char Bit1 : 1;
unsigned char Bit2 : 1;
unsigned char Bit3 : 1;
unsigned char Bit4 : 1;
unsigned char Bit5 : 1;
unsigned char Bit6 : 1;
unsigned char Bit7 : 1;
};

existe t-il un equivalent en c#

merci d'avance