Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Hex values and masking

152 views
Skip to first unread message

Matt

unread,
Aug 9, 2001, 11:53:54 AM8/9/01
to
Here is the problem.

I am trying to take a value from memory and mask this value so I can
then set a number of bits in the value and then return it to memory.
I read the value from memory and mask it. When I read the value from
memory I return a value for ex. Hex FFFF. When I mask this value the
final value turns out to be FFFF FFFF. How can this be? Also, I
cannot change bit 15 unless I use 65535 as the value for the constant.
If I use &HFFFF it will not change bit 15. The same is true in the
reverse for bits 0-14. Any suggestions.


'make the mask based on the number of bits the operator needs set
num = 0
for i = cint(startbit) to cint(endbit)
num = (2 ^ i) + num
next
makemask = num

memoryValue = SMActiveXObj.peekInt16ArrayElement(offsetValue,
cint(word))

'create mask and set bits for desired range. Remaining bits will
remain
'unchanged
constant = 65535 '&HFFFF
mask = makemask XOR constant

currentData = mask AND memoryValue

data = &H00FF 'or whatever value the operator wants set.
'set the data to send back to memory
setData = currentData OR data
setValue = SMActiveXObj.pokeInt16ArrayElement(offsetValue, cint(word),
setData)

Johnny Nielsen

unread,
Aug 9, 2001, 3:55:08 PM8/9/01
to
"Matt" <matthew....@saic.com> wrote in message
news:37dc8938.01080...@posting.google.com...

> I am trying to take a value from memory and mask this value so I can
> then set a number of bits in the value and then return it to memory.
> I read the value from memory and mask it. When I read the value from
> memory I return a value for ex. Hex FFFF. When I mask this value the
> final value turns out to be FFFF FFFF. How can this be? Also, I
> cannot change bit 15 unless I use 65535 as the value for the constant.
> If I use &HFFFF it will not change bit 15. The same is true in the
> reverse for bits 0-14. Any suggestions.

Why go through all the trouble typecasting ?

Your intermediate calculations will allways be correct as long as long as
you only use the logical operators, and if the
SMActiveXObj.pokeInt16ArrayElement function can't tolerate the excessive
highorder bits (which - without knowing the function - I'm rather sure it
will) you can mask the value using a MOD &H10000 just before passing it to
the function.


Best regards
Johnny Nielsen

0 new messages