Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

229
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda