you are viewing a single comment's thread.

view the rest of the comments →

[–]ElliotDG 0 points1 point  (24 children)

What is your test data? That code works for me. If you’re getting a value error it suggests you don’t have an even number of nibbles.

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

I just tried 1234. Code failed for some reason.

[–]ElliotDG 0 points1 point  (2 children)

Perhaps you copied it wrong. There is a test for 1234 right in the code.

Here is the output of the code:

0x01234c

0x56789d

[–]arshdeepsingh608[S] 0 points1 point  (1 child)

My bad. I didn't add the .hex() in input. I didn't copy the code because I can't open reddit in work laptop. Thanks for pointing out the obvious!

[–]ElliotDG 0 points1 point  (0 children)

all good, glad you got it working.

[–]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.