Read a bit value from an integer

0
Hello, I would like to read the 24th bit of an integer in Mendix. To do this, the integer would first have to be converted into a byte. Is there a function in Mendix for this? How can I read out the 24th bit?
asked
4 answers
1

There is no BITAND function, but you can work around it using MOD

(
  (
     $Bit24/Value - 
     ( 
        $Bit24/Value mod 
        pow( 2, 24-1 )
     )
  )
  div 
  pow( 2, 24-1 ) 
) mod 2 > 0

 

Thanks to Mathematically get n th bit from integer 

 

answered
0

As far as I can tell, this is not possible in Mendix, but you can create a Java action that will do this for you.

 

Java: Convert Int to a Byte (stackabuse.com)

answered
0

Okay, I have inserted an integer parameter in the Java action in Mendix (for the input from the microflow).

I think I should be able to use it in the Java file, but I can't find it. Here is an excerpt of the file:

package myfirstmodule.actions;

 

import com.mendix.systemwideinterfaces.core.IContext;

import com.mendix.webui.CustomJavaAction;

 

public class ConvertIntToByte extends CustomJavaAction<java.lang.Boolean>

{

    private java.lang.Long Parameter;

 

    public ConvertIntToByte(IContext context, java.lang.Long Parameter)

    {

        super(context);

        this.Parameter = Parameter;

    }

 

    @java.lang.Override

    public java.lang.Boolean executeAction() throws Exception

    {

        // BEGIN USER CODE

        throw new com.mendix.systemwideinterfaces.MendixRuntimeException("Java action was not implemented");

        // END USER CODE

    }

 

    /**

     * Returns a string representation of this action

     * @return a string representation of this action

     */

    @java.lang.Override

    public java.lang.String toString()

    {

        return "ConvertIntToByte";

    }

 

answered
0

I want to do it with this in the java file: 

// Convert integer to byte
    byte byteValue = (byte) integerValue;

    // read out 24th bit
    byte bitMask = (byte) (1 << 7);
    byte extractedBit = (byte) ((byteValue & bitMask) >>> 7);

 

but i dont know where i get the integerValue from and how i can return the boolean value, the file contains the above code

answered