Resolved Why is PUT-BITS and GET-BITS failing on 32bit integers?

Cecil

19+ years progress programming and still learning.
So I have some simple code which will loop through each bit of an integer and set the bits of a second integer variable, bit-by-bit.

However when it gets to position 32 in the integer it's failing.

Code:
DEFINE VARIABLE i  AS INTEGER  NO-UNDO.
DEFINE VARIABLE SourceNumber AS INTEGER  NO-UNDO.
DEFINE VARIABLE TargetNumber AS INTEGER  NO-UNDO format '-9999999999'.
SourceNumber = -9.
/** Working from LSB --> MSB / right to left */
DO i = 1 TO 32:
  PUT-BITS(TargetNumber, i ,1) = GET-BITS(SourceNumber, i ,1).
END.
DISPLAY  TargetNumber .
 

Stefan

Well-Known Member
Code works fine pre-int64 support (9.1E), so it seems like the 32-bit integer overflow check is being triggered. Use int64 and the problem is gone.

If you lookup the error message in 'recent messages' it claims to be an improved version of error 13682. This error message provides some useful hits:

site:knowledgebase.progress.com error13682
 
Last edited:

Cecil

19+ years progress programming and still learning.
Thanks for the insight into changing the data type to int64. I did see the KB about changing the INTEGER to INT64 but I felt like it was a workaround rather than a solution. I now know when dealing with PUT-BITS & GET-BITS it's beginning handled in a 64bit integer space (QWORD) regardless of variable's acutal integer data type. This was so confusing for me on why it was not working, IMHO I thought is was a bug.

I guess the PUT-BITS & GET-BITS are such a niche programming function that the average ABL/4GL Developer will never used them.

So here is my revised code.

Code:
DEFINE VARIABLE i                AS INTEGER     NO-UNDO.
DEFINE VARIABLE SourceNumber AS INTEGER     NO-UNDO.
DEFINE VARIABLE TargetNumber AS INT64     NO-UNDO format '-9999999999'.

SourceNumber = -9.

/** Working from LSB --> MSB / right to left */
DO i = 1 TO 64:
    PUT-BITS(TargetNumber, i ,1) = GET-BITS(SourceNumber, i ,1).
END.

DISPLAY  TargetNumber .
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
I guess the PUT-BITS & GET-BITS are such a niche programming function that the average ABL/4GL Developer will never used them.
Probably true. But some people really rely on them.

As an example, specifications like ANSI X9.2 and ISO 8583 (payment-card transaction messaging) and their many variants rely on variable-length message with bitmaps and there's a fair bit of bit-twiddling that goes on in the code. They date back to the days of slow, low-bandwidth comm lines with fixed packet sizes. In the old days, spec writers and developers had to be very clever about packing maximum meaning into minimum space. As time passed, the technology changed; the specs didn't, for the most part.
 
Top