reading four bits at a time from memory. C#

Posted on 2007-07-26
Medium Priority
Last Modified: 2008-01-09
How do I obtain four bytes from a memory offset. Using C#
 The units are in the high 32 bit integer(at Offset 0574) and the fractions are the low 32 bit integer
(at 0570 Offset in memory).

I guess I need to read an int, a byte from 0570 to --> 0577 and select the first four bits for one and the next four bits for the other.

My problem is how do I select four bits at a time. Is there a data type or do I split up the eight bits.
If so I dont know how ? thx.
Question by:rigidigital
  • 2
LVL 37

Expert Comment

ID: 19578013
split up the 8 bits ...

4bits = yourvalue & 0xF;




Accepted Solution

ravs120499 earned 1000 total points
ID: 19581515
Selecting 4 bits from a byte (or any other known length) value is easy:

"right-most" (i.e. least significant) 4 bits = bytevalue & 0xF (as greg young said).
left-most (most significant) 4 bits = bytevalue & 0xF0.

But I did not understand the part about the high-32 and low-32 parts. If the underlying data is in two separate 32-bit slots, why do you need to divide it into 4-bit nibbles?

- Ravs

Author Comment

ID: 19582698
Look I made error here. Terminology is new however basic. You picked it up, I have confused bits and bytes.  Im trying to sort out electrical probs and just getting confused with programming! The bits I want is more like 4 bytes.
LVL 37

Assisted Solution

gregoryyoung earned 1000 total points
ID: 19582716
Then just read the memory as an integer ... or if you have it as a long ...

value & 0xFFFFFFFF; //gets low 32 bits


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question