Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am not quite sure what you are asking, but I can tell you a way to access individual bits in a byte, which is perhaps what bitsets do. Mind you that the following code is not my own and is Microsoft spec (!).</p> <p>Create a struct as such:</p> <pre><code>struct Byte { bool bit1:1; bool bit2:1; bool bit3:1; bool bit4:1; bool bit5:1; bool bit6:1; bool bit7:1; bool bit8:1; } </code></pre> <p>The ':1' part of this code are bitfields. <a href="http://msdn.microsoft.com/en-us/library/ewwyfdbe(v=vs.80).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ewwyfdbe(v=vs.80).aspx</a> They define how many bits a variable is desired to occupy, so in this struct, there are 8 bools that occupy 1 bit each. In total, the 'Byte' struct is therefore 1 byte in size.</p> <p>Now if you have a byte of data, such as a char, you can store this data in a Byte object as follows:</p> <pre><code>char a = 'a'; Byte oneByte; oneByte = *(Byte*)(&amp;a); // Get the address of a (a pointer, basically), cast this // char* pointer to a Byte*, // then use the reference operator to store the data that // this points to in the variable oneByte. </code></pre> <p>Now you can access (and alter) the individual bits by accessing the bool member variables of oneByte. In order to store the altered data in a char again, you can do as follows:</p> <pre><code>char b; b = *(char*)(&amp;oneByte); // Basically, this is the reverse of what you do to // store the char in a Byte. </code></pre> <p>I'll try to find the source of this technique, to give credit where credit is due.</p> <p>Also, again I am not entirely sure whether this answer is of any use to you. I interpreted your question as being 'how would access to individual bits be handled internally?'.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload