Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loading an int with bits

Status
Not open for further replies.

DerPflug

Programmer
Mar 28, 2002
153
0
0
US
What is the proper way to load a 32-bit integer with 23 bit values from a database? For instance, I have a database record with 23 fields that are a bit datatype. I want to load those 23 fields' values into a 32-bit integer value and return it as one value to be parsed in a different function. Is this the idea?:

intValue = first_bit_field_value;
intValue = intValue + (second_bit_field_value * 2);
intValue = "" + (third_ "" * 4);
"" "" * 8);
"" "" 16
"" "" 32
"" "" 64
"" "" 128
"" "" 256
"" "" 512

etc...

Any help would be appreciated.
 
You can just set the bit with something like (Solaris):

var |= (1 << bit_to_set);
----------------------

...

var |= (1 << 0); /*First bit ... shift 0 bits*/
var |= (1 << 1); /*Second bit ... shift 1 bit*/

printf(&quot;%d\n&quot;, var); /* Prints 3 (8-bits example) 00000011*/



Just something to think about. ;-)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top