News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Bitwise question

Started by lamer, November 15, 2005, 12:55:15 PM

Previous topic - Next topic

lamer

Hi all!
Suppose the following:

mov eax,12345
or eax,98765
;now eax=111101
test eax,98765
.if !ZERO?
    ;I want to get 12345
    xor eax,98765
    ;but I get 12336 ::)
.endif

So, how can I extract 12345?

Thank you.

Tedd

Those number are decimals. The concept you're trying to use doesn't really work so well when each digit takes up a fractional number of bits.
Try using hex numbers instead (octal will also work.)

As for OR'ing - you're in trouble. It gives no indication of which bits have been overwritten and which haven't.
XOR can be undone with another XOR, but OR 'destroys' the past state.

What are you trying to do? Maybe there's a different way around it.
No snowflake in an avalanche feels responsible.

lamer

I am trying to store two DWORDs as lParam of TV_ITEM.
And then, moving through the tree view, check whether the lParam of current item includes the second DWORD. If so - extract the first DWORD and use it. They must be DWORDs, otherwise I would use MAKEWORD. Actually, I have found another solution, but I am still interesting how to solve the problem.

ramguru

imho it's impossible to store two DWORDs in one DWORD unless you place a pointer to some other data...but it isn't very clever  :lol

Tedd

The general solution to your problem is to store an index/pointer as the lParam, and then use this to look-up in your own list to access whatever information you require. You can't just store everything as part of the tree-view.

If you could store two DWORDs in one, that would be a very nice compression algorithm. And just think, if you could store two, then you could store another on top of that because the first composite is just a dword anyway. And then you could store another on top of that, and on top of that.... thus storing any amount of data in one single DWORD :bdg
But, sadly, it's not possible. Damn reality!!
You could potentially cheat, by limiting the range of each field - but in a symmetrical case this would equate to two WORDs anyway (it just depends where you choose the splitting point.)
No snowflake in an avalanche feels responsible.

subhadeep_ghosh

Lamer...can't do much about it dude sorry... :bg
Take a look at the following example and you might find out why it is an impossibility...
Consider these two numbers....
NUM1 = 61680 in decimal and 1111000011110000 in binary
NUM2 = 15420 in decimal and 0011110000111100 in binary
So the result of NUM3 = NUM1 or NUM2 would be 64764 in decimal or 1111110011111100 in binary
Now when u NUM4 = NUM3 xor NUM2, you get 49344 in decimal or 1100000011000000 in binary.

So the problem is this...

       1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 NUM1
or   0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 NUM2
------------------------------------------------
       1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 NUM3

Now let's compair the result (NUM3) with NUM2....

       0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 (NUM2)
       1 1 1 1 1 1 0 0 1 1 1 1 1 1 0 0 (NUM3)

Bit positions 0 and 1 are zero so we do not bother about them.
Incase of bit position 2, NUM2 has a '1' and now there is no way of knowing if there was a '1' at the bit position 2 of NUM1 or not because 1 or 1 = 1 and also 1 or 0.
Same is the case for bit position 3.
Incase of bit position 4 again we are sure that there is a '1' at the bit position 4 of NUM1. And same is the case of bit position 5...and so on....
'Or' and 'And' are two functions which have one output for 3 different inputs...
Or
    1 or 0 = 1
    1 or 1 = 1
    0 or 1 = 1

And
    1 and 0 = 0
    0 and 0 = 0
    0 and 1 = 0

So if we are given one output for any of the operations and asked to derive the input then it is impossible, coz there were 3 inputs for the same output so there is no way of knowing that the output which you got came from which of the 3 inputs.