PFC Guide Titlebar
HomeFAQLinksPFCMAGExtensionsDownloadWhat's NewSearch

Numeric Service FAQ


Table of Contents

  1. What is the purpose of the Numerical Service?
  2. What are the limitations of the Numerical Service?
  3. How do I overcome the Numerical Service Limitations?

What is the purpose of the Numerical Service

Contributed by Lijun Yang.

The purpose of the numerical service is to simulate bitwise operations and provide a way to convert data between decimal and binary. The binary data is represented by strings. For example, 11111 is represented by "11111."

There are seven functions in the numerical service. They are:

Function Name Return Type Description
Of_Binary (long al_decimal) string Convert a decimal value to its binary equivalent
Of_Decimal (string as_binary) long Convert a binary value to its decimal equivalent
Of_BitwiseAnd (long al_value1, long al_value2 long Simulate bitwise AND operation
Of_BitwiseOr (long al_value1, long al_value2) long Simulate bitwise OR operation
Of_BitwiseXor (long al_value1, long al_value2) long Simulate bitwise XOR operation
Of_BitwiseNot (long al_value) long Simulate bitwise NOT operation
Of_GetBit (long al_decimal, unsignedinteger ai_bit) boolean Determine the bit value for a specified position

The service can serve as a handy object for occasional binary operations, such as user ID and password encryption and decryption. Another advantage is that it is a pure PowerBuilder object and can be used in multiple platforms.

Back to Top

What are the limitations of the Numerical Service?

Contributed by Lijun Yang.

One limitation is that the value of binary data must be not greater than 31 bits. If you convert a 32 bit binary data, you will get an incorrect decimal result. As discussed above, the purpose of the service is to simulate bitwise operations. An individual bit is represented by 0 or 1. There is no sign. Thus it is more accurate to use unsigned long to represent its decimal equivalent. When decimal value is of ulong type, the conversion error will be corrected

Another limitation is the slow performance of bitwise operations. of_GetBit() unnecessarily uses Boolean data to represent the 0 and 1 bit value and largely impacts the performance of bitwise operations. When you inspect the code, you will find the decimal data is at first converted into Boolean value and then reconverted into decimal data.

Back to Top

How do I overcome the Numerical Service Limitations?

Contributed by Lijun Yang.

In order to overcome the first limitation, you can extend the service by using ulong type in place of long for decimal value. By doing so, you can get the correct conversion between binary and decimal values.

To overcome the second limitation, one option is to change the return type of Of_Getbit() from Boolean to ulong or uint. Another option is to find Powerscript equivalents for bitwise operations as shown in Numerical Service Extension. If you use bitwise operations very intensively, you may choose C or C++ to implement the functionality.

Back to Top

Contributed by PFCGuide staff, except where noted otherwise.
PFCGuide is sponsored by Dynamic Technology Group.
The information provided is for advice only and not to be considered a contract or a liability against Dynamic Technology Group.

Last revised: February 15, 2004 03:58 AM.