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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Memory overlay

Status
Not open for further replies.

TheObserver

Programmer
Mar 26, 2002
91
US
Let's say I have four bytes of memory:
10110001 11100011 11001100 10111011

and I want to overlay/update/merge those four bytes with a pattern such as this:

00000000 00000000 11101001 11111101

such that bytes three and four are updated to the value in the map/overlay and bytes one and two stay unchanged from the original.

IE, the result would be:
10110001 11100011 11101001 11111101

How could I go about doing this, logically? An OR has been suggested, but I don't think that will work.

Thanks for your time.
 
For that particular example:
Code:
(
   10110001 11100011 11001100 10111011
   or
   00000000 00000000 11111111 11111111
)
and
(
   00000000 00000000 11101001 11111101
   or
   11111111 11111111 00000000 00000000
)
 
It's not clear what you actually want.

how about
{
unsigned char orig[4] = { 0xB1, 0xE3, 0xCC, 0xBB };
unsigned char tmplt[4] = { 0x00, 0x00, 0xF9, 0xDD };

orig[2] = tmplt[2];
orig[3] = tmplt[3];
}

or
{
unsigned char orig[4] = { 0xB1, 0xE3, 0xCC, 0xBB };
unsigned char tmplt[4] = { 0x00, 0x00, 0xF9, 0xDD };

for (int i = 0; i < sizeof(orig); i++) {
if (tmplt != 0) orig = tmplt;
}
}
 
You don't want an OR, you want a LOR (logical or). A LOR will OR each bit into the result. Really a different thing from OR.

Very simple example:

Code:
	unsigned long a = 2; // i.e. 0010
	unsigned long b = 1; // i.e. 0001
	unsigned long d = 4; // i.e. 0100
	unsigned long result;

	result = a | b; // will return '3' i.e. 0011 < 0001 | 0010
	result = result | d; // will return '7' i.e. 1111 < 0100 | 0011

The operator &quot;||&quot; is OR, &quot;|&quot; is LOR.
 
Correction to previous:

Code:
result = result | d; // will return '7' i.e. 0111 < 0100 | 0011
 
If I understand what you mean, you want :

1. Clear the 3rd and 4th bytes of the first string :

10110001 11100011 11001100 10111011
AND
11111111 11111111 00000000 00000000
----------------------------------------
10110001 11100011 00000000 00000000

2. Clear the 1st and 2nd bytes of the second string :

00000000 00000000 11101001 11111101
AND
00000000 00000000 11111111 11111111
----------------------------------------
00000000 00000000 11101001 11111101

( It does not change a thing in this example )

3. Merge the resulting strings :

10110001 11100011 00000000 00000000
OR
00000000 00000000 11101001 11111101
----------------------------------------
10110001 11100011 11101001 11111101

It would look something like that

( s1 AND 0xFF00 ) OR ( s2 AND 0x00FF )

Voila :)
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top