![]() |
|
laziness, impatience, and hubris | |
PerlMonks |
comment on |
( #3333=superdoc: print w/replies, xml ) | Need Help?? |
Lines 21 thru 23 of the following example demonstrate operations on individual bits, specified by their position, of a status word. The difficulty arises when we need to input or output this word. We need the bytes in the order that our hardware expects them ("endianness") and we want the position 0 to refer to the most significant bit.
I created a disc file which contains nothing but a 16-bit status word and verified the exact contents of that file with the utility "xxd" (came packaged with vim). My example reads that status word, makes a few changes, and writes it back out to another file. Again I use xxd to verify that I made the changes that I intended. OK, I admit that lines 11 thru 19 and 25 thru 33 were developed empirically for this use of vec on my 64-bit intel machine. They are not portable to other environments but should work, without change, on any application on this or similar machine.
Here is the content of the two data files (displayed by xxd) after this example runs
Note: There is no guarantee that traditional bit masking will eliminate this problem in I/O. It might, but testing is still required.
Bill
In reply to Re^3: How can I set a bit to 0 ?
by BillKSmith
|
|