Bits

rifter1818 said:
Is there any way to Access Memory one bit at a time? Have say 9699690 bits of memory 1s and 0s and read and write to each memory bit?
1. Point to your memory and cast as a Int64[]
2. Grab each Int64 containing the bit you want to change.
3. Perform Bitwise arithmetic on the Int64 to modify the nth bit

to set bit n : myInt64 |= Math.Pow(2,n-1);
to clear bit n : myInt64 = ~(( ~myInt64 ) ^ ( Math.Pow(2,n-1) ));

There might be a more efficient method for the bit clear, but that should work.
Boolean algebra was always confusing to me.

joe mamma
 
Last edited by a moderator:
Joe Mamma said:
1. Point to your memory and cast as a Int64[]
2. Grab each Int64 containing the bit you want to change.
3. Perform Bitwise arithmetic on the Int64 to modify the nth bit

to set bit n : myInt64 |= Math.Pow(2,n-1);
to clear bit n : myInt64 = ~(( ~myInt64 ) ^ ( Math.Pow(2,n-1) ));

There might be a more efficient method for the bit clear, but that should work.
Boolean algebra was always confusing to me.

joe mamma


You can always have the BitArray Class do the math for you :D
 
rifter1818 said:
Is there any way to Access Memory one bit at a time? Have say 9699690 bits of memory 1s and 0s and read and write to each memory bit?

Are you sure you mean one bit at a time and not one byte? If you did mean bit, try the suggestions above. If you meant byte, just create a byte array. Now if you want a specific chunk of memory thats a bit different. If you want a chunk in another process (not from your app, but someone elses) thats yet another story.

-ner
 
clarification of my original

rifter1818 said:
Is there any way to Access Memory one bit at a time? Have say 9699690 bits of memory 1s and 0s and read and write to each memory bit?
I just want to clarify that you need to work with the values in the array, as I am afraid, you might not get what you are looking for.


1. Point to your memory and cast as a Int64[], myInt64s
2. Advance to the Int64 containing the bit you want to change.
3. Perform Bitwise arithmetic to modify the nth bit of myInt64s

to set bit n : myInt64 |= Math.Pow(2,n-1);
to clear bit n : myInt64 = ~((~myInt64)^(Math.Pow(2,n-1)));

There might be a more efficient method for the bit clear, but that should work. Boolean algebra was always confusing to me.

joe mamma
 


Write your reply...
Back
Top