Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)
Is there any way to Access Memory one bit at a time? Have say 9699690 bits of memory 1's and 0's 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

Edited by Joe Mamma

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Posted
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

  • *Experts*
Posted
Is there any way to Access Memory one bit at a time? Have say 9699690 bits of memory 1's and 0's 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 that's a bit different. If you want a chunk in another process (not from your app, but someone else's) that's yet another story.

 

-ner

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Posted

clarification of my original

 

Is there any way to Access Memory one bit at a time? Have say 9699690 bits of memory 1's and 0's 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

Joe Mamma

Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized.

Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...