Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

227
Vistas
How do I create a 3 bit variable as datatype in C?

I can typedef char to CHAR1 which is 8 bits. But how can I make 3 bit variable as datatype?

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

You might want to do something similar to the following:

struct
{
  .
  .
  .
  unsigned int fieldof3bits : 3;
  .
  .
  .
} newdatatypename;

In this case, the fieldof3bits takes up 3 bits in the structure (based upon how you define everything else, the size of structure might vary though).

This usage is something called a bit field.

From Wikipedia:

A bit field is a term used in computer programming to store multiple, logical, neighboring bits, where each of the sets of bits, and single bits can be addressed. A bit field is most commonly used to represent integral types of known, fixed bit-width.

over 4 years ago · Santiago Trujillo Denunciar

0

It seems you're asking for bitfields https://en.wikipedia.org/wiki/Bit_field Just be aware that for some cases it's can be safer just use char or unsigned char instead of bits (compiler specific, physical memory layout etc.)

Happy coding!

over 4 years ago · Santiago Trujillo Denunciar

0

typedef struct {

int a:3;
}hello; 

It is only possible when it is inside structure else it is not

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda