News:

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

Un Or

Started by Gunner, February 02, 2010, 10:38:02 PM

Previous topic - Next topic

Gunner

How would I get the values of some number?  I.E. when we create a window we OR numbers together WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE which is 12582912 or 131072 or 524288 or 268435456  all ORd together comes to 281673728 how do I "extract" back to the original numbers?  How would I know what numbers are OR'd together?  I want to grab a number from the registry, "un OR" it and set some checkboxes according to what was ORd together.  Make sense?/+
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

oex

Check bits set? BT operator

(I think)
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

FORTRANS

   Most of the time you or things together,
they make more sense as hexadecimal.

   Decimal       Hex
   12582912     C00000 
     131072      20000
     524288      80000
  268435456    1000000


Steve

qWord

simply test for each constant (WS_ ...)
e.g.:

...
test dwFlags,WS_CAPTION
.if !ZERO?
    invoke SendMessage,hWnd_ChkCaption,BM_SETCHECK,BST_CHECKED,0
.else
    invoke SendMessage,hWnd_ChkCaption,BM_SETCHECK,BST_UNCHECKED,0
.endif

test dwFlags,WS_VISIBLE
.if !ZERO?
    invoke SendMessage,hWnd_ChkVisible,BM_SETCHECK,BST_CHECKED,0
.else
    ...
.endif
...


EDIT: a better approach is mov eax,dwFlags
and eax,WS_VISIBLE
cmp eax,WS_VISIBLE
je @visible
FPU in a trice: SmplMath
It's that simple!

dedndave

you could use a few EQUates to form a mask
i say "a few" because the boolean statements can get kind of long in the tooth
best to keep this all in hexidecimal - it is easier to understand
in the example you mentioned, you have these bits set

WS_CAPTION      equ 0C00000h
WS_MINIMIZEBOX  equ 20000h
WS_SYSMENU      equ 80000h
WS_VISIBLE      equ 10000000h

WS_CAPTION or WS_MINIMIZEBOX or WS_SYSMENU or WS_VISIBLE = 10CA0000h

if i wanted to create a mask to isolate WS_VISIBLE, i would do something like this

WS_VIS_MASK     equ not WS_VISIBLE   ;0EFFFFFFFh

by using NOT, AND, OR, XOR, you can create whatever mask you want

but, if you want to take a dword value and turn it into an ASCII string of pin names, you are out of luck   :P

Gunner

The WM_ stuff was just an example, the following are the equates that I would need to break a number back down to:

0x00000001
0x00000002
0x00000004
0x00000008
.. 10
.. 20
.. 40
.. 80
.. 100
.. 200
.. 400
.. 800
.. 1000
.. 2000
.. 8000
.. 10000
.. 20000
.. 40000
.. 100000


These are edit flags in the registry... and depending on what flags are set I want to toggle check boxes.  I think I asked a similar question 5+ years ago on the old board but there is no way to search the old forum  :(
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

dedndave

well - it depends a lot on your exact application
because, you may want to isolate 2 bits in one case or 6 bits in another, for example
in other words, it depends on exactly what you need
but, for what you have mentioned, you can make an inverted set of EQUates for each of the others

bit00     equ 00000001h
bit01     equ 00000002h
bit02     equ 00000004h
bit03     equ 00000008h
bit04     equ 00000010h
bit05     equ 00000020h
bit06     equ 00000040h
bit07     equ 00000080h
bit08     equ 00000100h
bit09     equ 00000200h
bit10     equ 00000400h
bit11     equ 00000800h
bit12     equ 00001000h
bit13     equ 00002000h
bit14     equ 00004000h
bit15     equ 00008000h
bit16     equ 00010000h
bit17     equ 00020000h
bit18     equ 00040000h
bit19     equ 00080000h
bit20     equ 00100000h
bit21     equ 00200000h
bit22     equ 00400000h
bit23     equ 00800000h
bit24     equ 01000000h
bit25     equ 02000000h
bit26     equ 04000000h
bit27     equ 08000000h
bit28     equ 10000000h
bit29     equ 20000000h
bit30     equ 40000000h
bit31     equ 80000000h

masks:

bit00_not equ not bit00
bit01_not equ not bit01
bit02_not equ not bit02
bit03_not equ not bit03
bit04_not equ not bit04
bit05_not equ not bit05
bit06_not equ not bit06
bit07_not equ not bit07
bit08_not equ not bit08
bit09_not equ not bit09
bit10_not equ not bit10
bit11_not equ not bit11
bit12_not equ not bit12
bit13_not equ not bit13
bit14_not equ not bit14
bit15_not equ not bit15
bit16_not equ not bit16
bit17_not equ not bit17
bit18_not equ not bit18
bit19_not equ not bit19
bit20_not equ not bit20
bit21_not equ not bit21
bit22_not equ not bit22
bit23_not equ not bit23
bit24_not equ not bit24
bit25_not equ not bit25
bit26_not equ not bit26
bit27_not equ not bit27
bit28_not equ not bit28
bit29_not equ not bit29
bit30_not equ not bit30
bit31_not equ not bit31

Gunner

Hmmm, thanks will try out
~Rob (Gunner)
- IE Zone Editor
- Gunners File Type Editor
http://www.gunnerinc.com

Astro

Hi,

If you have two values:

0100101101 - value 1
1010101001 - value 2

and you OR them together:

0100101101
1010101001 OR
=========
1110101101 - composite value

you then end up with a composite number.

To determine if a value you are looking for exists in the composite (you will note the WM_ values use patterns that can't create other WM_ values), such as value 2, you AND the composite and the value you are looking for together:


1110101101 (composite)
1010101001 AND (value 2)
=========
1010101001 - matches value 2, so value 2 exists in the composite value (result AND value2)

If you AND another pattern together, that doesn't exist, it won't match.

Best regards,
Robin.

drizz

flags are usually powers of two so AND is the reverse operation (extraction) of OR (insertion)
Quote from: Gunner on February 02, 2010, 10:38:02 PM... which is 12582912 or 131072 or 524288 or 268435456  all ORd together comes to 281673728 ....
It's time you start thinking in base 2  :wink
The truth cannot be learned ... it can only be recognized.

redskull

If you do a lot of work with those flag-style fields, MASM has built in functions to handle them, the main ones which are RECORD, MASK, and WIDTH.  RECORD is similar to struct, except you define the lengths of bits, and MASK will return a bitmask corresponding to those positions.  It's no more efficient than just using defined constants, except that it makes the declaration simpler in that you define the widths, and MASM figures out the hex constant to use.

-r
Strange women, lying in ponds, distributing swords, is no basis for a system of government

dedndave

QuoteIt's time you start thinking in base 2

we'll cut off 9 of his fingers and make him count to 128   :P

after a while, your brain starts to think like a (slow) cpu