Question

Bitmask resolving

  • 16 October 2013
  • 7 replies
  • 2 views

Badge +11
Hi there, 

 

 

in order to find the values 1, 2 , 4, 256, 512 and 1024 in a bitmask, I created 6 ExpressionEvaluators, all writing to a different attribute. The Expression is of the kind '@Value(BLOCKAGE_MASK) & 1'. 

 

 

Although, it perfectly does what I intend to, I have the feeling that it is quite laborious, handling all these extra attributes.

 

So, just to improve my skills: is there a better way to resolve bitmasks in FME? I was thinking about creating a list of all the values of the bitmask. For example, 771 would return a list with elements 1, 2, 256 and 512. A ListSearcher could be used afterwards.

 

 

I can't find a dedicated bitmask transformer through documentation, nor on the forum here. But that is moslty the toughest part in FME.

 

 

Any advice would be welcome, probalbly also for future reference.

 

 

 

best regards, 

 

Jelle

 

 

 


7 replies

Userlevel 4
Hi Jelle,

 

 

I have never seen anything bitmask-related in the FME transformer gallery. Your solution was quite elegant, so thanks for sharing.

 

 

An alternative solution might be either to create a custom transformer or to do something with a PythonCaller.

 

 

For example, here is how you can convert a decimal number into a binary string representation using Python:

 

 

def bin(s):     return str(s) if s<=1 else bin(s>>1) + str(s&1)

 

 

Example: bin(873) -> '1101101001'

 

 

It is then quite easy to check the individual characters using e.g. a SubstringExtractor.

 

David
Badge +11
Hi David, 

 

 

thanks for your prompt reply. With Python, everything is possible of course. I try to avoid it when I find a workaround. 

 

 

A standard bitmask resolver in FME could probably be useful to many people. It should be possible to develop, I think. For now, I'll continue to use the workbench like I've developed it.

 

 

 

best regards, 

 

Jelle
Userlevel 4
Yes, anything is possible with Python, although I agree that it is usually better to avoid it if there's a solution closer to FME.

 

 

If you do make such custom transfomers, perhaps consider publishing them on the FME Store?

 

 

David
Badge +11
Hi Takashi,

 

 

nice to have your reply as well. I think, all ways all valuable. I know a bit of Python, but TCL is completely new to me. I think I understand the code, though.

 

Having several options is one of the big benefits of FME, indeed.

 

 

 

best regards, 

 

Jelle

 

 

Userlevel 2
Badge +17
I found a way to set a list attribute in the TclCaller.

 

Replace the last line ("join ...") in the previous procedure with these lines.

 

-----

 

  for {set i 0} {$i < [llength $result]} {incr i} {

 

    FME_SetAttribute "_list{$i}" [lindex $result $i]

 

  }

 

-----

 

 

There are many things I have to learn!

 

 

Regards, Takashi
Badge +11
We all do. Congrats!
Badge +11
Hi David and Takashi, 

 

 

I've received an interesting reply from Safe Support:

 

 

With the new AttributeCreator and the ability to embed complex and conditional arithmetic expressions in the definition, you should be able to replace your 6 expression evaluators with one AttributeCreator. 

 

 

I forgot about this new possibility, but I think this is a good example of how to use it.

 

 

Thanks @SafeSupport!

 

 

 

best regards, 

 

Jelle

 

 

Reply