Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to set the value of an variable by the bits to comprise it?

I am trying to make a hamming code decoder and encoder in C and I cannot find a way to set the bits of a variable individually.

For example, I am trying to somehow do the following:

#include "stdio.h"

int main () {
    short block = 0010101110001110; // variable to contain the bits to decode
}

Clearly this will not work but I am wondering if there is a way to do this or will I have to define it as the actual number this represents?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use hexadecimal representation, where each digit represents exactly 4 bits.

unsigned short block = 0x2b8e;
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading