KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Inverting a Long Int number
PRODUCT: 4D | VERSION: 14.3 | PLATFORM: Mac & Win
Published On: March 26, 2015

Here is a method to invert a long int number:

// ----------------------------------------------------------------------
// Name: INVERT_LONGINT
// Description: Method will take in a Long Int number and invert using
// Exclusive OR.
//
// Parameters:
// $1 (LONG INT) - Input of the Long Integer
// Output:
// $0 (LONG INT) - Output of the Long Integer inverted.
// ----------------------------------------------------------------------
C_LONGINT($1;$LongInt_Input)
C_LONGINT($0)

$LongInt_Input:=$1

Case of
   :(($LongInt_Input>0) & ($LongInt_Input<=255)) // (0x00 - 0xFF)
   $0:=$LongInt_Input ^| 255

   :(($LongInt_Input>255) & ($LongInt_Input<=4095)) // (0x100 - 0xFFF)
   $0:=$LongInt_Input ^| 4095

   : (($LongInt_Input>4095) & ($LongInt_Input<=65535)) // (0x1000 - 0xFFFF)
   $0:=$LongInt_Input ^| 65535

   : (($LongInt_Input>65535) & ($LongInt_Input<=1048575)) // (0x10000 - 0xFFFFF)
   $0:=$LongInt_Input ^| 1048575

   else
   $0:=$LongInt_Input ^| 16777215 // (0x100000 - 0xFFFFFF)
end case



An example of a Long Int inverted:

C_LONGINT($input_value;$inverted_value)

$input_value:=826368

$inverted_value:=INVERT_LONGINT($input_value) // $inverted_value (222207)

See Also: