View previous topic :: View next topic
|
Author |
Message |
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
Hi, I have a Incoming message with compressed data (binary format), as below,
Hex format: x'005705D121022250'.
If its the Tag 0057 (two bytes) is found, the next byte is the length (here it is 05), then i need to populate next 5 bytes to a common variable (x'D121022250').
The Problem is the half byte 'D' is a junk data that should not be moved to common variable, the data movement should be as x'1210222500' (adding 0 as the last nibble since D was removed).
Could someone can help me out,? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Multiply by 16 will shift left a half-nybble. Use COMP-5 and no sign. Big COMP-5. Put your value in the low-order five bytes (via REDEFINES) and multiply. Move it back out. Your "D" will evaporate at the left and zero appear as if by magic at the right. |
|
Back to top |
|
|
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
Hi Bill, Thanks for your thoughts, But could you please explain further (pseudo code), Your suggestion is really appreciated but it ll be great if u explain with example,, |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You have five bytes of binary data. In Cobol, you can't define five bytes. as you get given a minimum size (which you could descibe as "twice times the 'boundary' already exceeded, or two bytes, whichever is bigger'.
So, you need eight bytes. So you define a binary item which is eight bytes long - you have to choose the correct number of 9s, or at least enough to make it eight bytes long and best to have at least as many 9s you need to represent the maximum value in your five-byte field.
Don't make the field signed. It won't matter in this case, but if you unthinkingly copy the code for something similar, it might matter.
Make the field COMP-5. Again, it won't matter in this case, but the same advice.
Now redefine that as a FILLER of 3 and a named-field of 5.
Put your five-byte value into the five bytes of the redefinition.
Now multiply the COMP-5 by 16, putting the result in the same COMP-5.
Why 16? If it is base-10, and you have a number 9876, and you multiply by 10, you get 8760, the effect you want. 'Binary' is, for us humans, in base-16. So multiply by 16.
Now you can move the five-byte field to your final destination.
There are other ways, but this is straightforward. Give everything nice clear names, relevant to the task, And document it, both inside and outside the program.
EDIT: In the cold light of day, I noticed I left this out:
Put your five-byte value into the five bytes of the redefinition.
I have added it in the appropriate place. |
|
Back to top |
|
|
dudenithy
New User
Joined: 02 Mar 2012 Posts: 48 Location: India
|
|
|
|
Thanks Bill for your well explained suggestion. Will try this out |
|
Back to top |
|
|
|