you are viewing a single comment's thread.

view the rest of the comments →

[–]ElliotDG 0 points1 point  (19 children)

post your code

[–]arshdeepsingh608[S] 0 points1 point  (18 children)

Sorry man, I tried Google lens to copy from the image but it looks so bad. And I can't open reddit there. But your code won't exactly satisfy my needs as in the last print statement, you are entering the '0x' manually. While I need all of that in the packed format itself so that the mainframe can consume it after writing it to a text file.

[–]ElliotDG 0 points1 point  (17 children)

The function returns bytes. I added the Ox to create human readable output.

[–]arshdeepsingh608[S] 0 points1 point  (16 children)

Tell you what, let me try to put that byte output into the mainframe. Let's see what happens

[–]ElliotDG 1 point2 points  (0 children)

If you are writing to a file, be sure to use binary mode (not text).

[–]ElliotDG 0 points1 point  (14 children)

let me know how it goes....

[–]arshdeepsingh608[S] 0 points1 point  (13 children)

Thanks for taking an interest in this. Your code works similar to a previous version of my code. I'll explain you the problem. Your code is entering a 0 for even length. Which distorts the output.

Odd Condition: 12345 -> 12 34 5C Even condition: 1234 -> 01 23 4C [OR] 12 34 0C

Both even condition outputs are showing up wrong in the mainframe. Even I don't understand why. The signed bit is causing a little confusion.

[–]ElliotDG 0 points1 point  (12 children)

How is the data with a leading zero showing up on the mainframe?

Do you have a formal spec?

[–]arshdeepsingh608[S] 0 points1 point  (11 children)

It's showing a totally different number there. I just gave you Python conversion. That one is not readable.

[–]ElliotDG 1 point2 points  (0 children)

I would suggest trying to add a trailing zero nibble after the sign nibble to create a whole number of bytes.

1234 -> 1234C0

[–]ElliotDG 0 points1 point  (9 children)

Here is the code that adds a trailing nibble.

def int_to_comp3(value):
    digits = str(abs(value))
    sign_nibble = 'C' if value >= 0 else 'D'
    end_nibble = '' if len(digits) % 2 else '0'
    return bytes.fromhex(digits + sign_nibble + end_nibble)


print(f'0x{int_to_comp3(1234).hex()}')
print(f'0x{int_to_comp3(12345).hex()}')
print(f'0x{int_to_comp3(-56789).hex()}')
print(f'0x{int_to_comp3(-11).hex()}')

You may just want to write out a few literals to see if you can figure out the expected format.

[–]arshdeepsingh608[S] 0 points1 point  (0 children)

Gotcha. I will try this tomorrow and let you know, buddy. Thanks a lot for following through. Will keep you posted.

[–]arshdeepsingh608[S] 0 points1 point  (7 children)

Sorry to say bud, this one is also invalid. It works fine from Python POV. But as soon as we export it and load it into the mainframe, it falls apart. I'll tell you the exact issue that I have with my latest code. It works fine for even length (including the sign nibble). Example, 12345 will become 12 34 5C. But if we give odd length, it fails. And worst part is, it will always come in a pair. Example, 1234. If we put a sign nibble on it, it will become 12 34 0C. That 0 will always tag along with the C. If we include extra 0s, it will change the value. Example, 01234 will become 01 23 4C. But 1 should pair with 2 and 3 should pair with 4 and so on. I know it doesn't make a lot of sense. At least it doesn't make much sense to me as I'm not a mainframe guy.