Page 1 of 1

Convert ZD field to Negative Binary

Posted: Sat Jan 25, 2025 2:56 am
by ianc
I have a dataset with a small number of records with a 'sign' character, follow by a 10 character ZD number. If the 'sign' is - then I need to convert it to the binary negative equivalent, if it's + then I need to convert it to the binary equivalent. For example, I created a simple test with the following

Code: Select all

//SORTIN DD *
+0000000011
-0000000011
/*


Using this data I need to just convert the number in the first record to binary and the number in the second record to the negatie binary value (ie The first character is driving the positive/negative conversion)

I'm using the following SORT statements

Code: Select all

SORT FIELDS=COPY
OUTREC IFTHEN=(WHEN=INIT,BUILD(1,1,2,10,ZD,TO=BI)),
  IFTHEN=(WHEN=(1,1,CH,EQ,C'-'),OVERLAY(2:2,4,ZD,TO=FS,LENGTH=4)


The job runs to CC=0.

However, when I look at the generated records, the first positive number is correct, however the second number has had the leading zeros replaced with spaces x'40'.

Record 1 - 4E000000 0B000000
Record 2 - 60404040 FB000000

Red indicates the spaces where I expected zeros.

I looked in the DFSORT OPTIONS to see if there was something to control this but couldn't see anything.

Any thoughts appreciated!

Re: Convert ZD field to Negative Binary

Posted: Sun Jan 26, 2025 2:50 am
by sergeyken
After conversion to BI your field (2,4) is neither ZD format, nor can be converted to FS. It just makes no sense.

In order to change the sign of your binary field, you must multiply its content by -1, in binary format, but not ZD or FS.

Re: Convert ZD field to Negative Binary

Posted: Sun Jan 26, 2025 3:07 am
by sergeyken
FYI:

In binary format, the value -11 is stored in memory as X’FFFFFFF5’
While the value +11 is X’0000000B’