Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How do I convert COBOL Comp-3 packed to ASCII?
Message
From
06/03/2003 21:17:32
 
 
To
06/03/2003 19:51:39
James Hansen
Canyon Country Consulting
Flagstaff, Arizona, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00762419
Message ID:
00762553
Views:
35
>"Packed decimal" format depends on the machine it came from. This may not be the old IBM 360/370 Packed Decimal, but based on your description: Each digit is stored as a "nibble", four bits of a byte with a sign byte preceeding them. If all the numbers are 6 bytes long as in your example, then if you read in six bytes into a string variable S, you could decode the value into Y as:
>
>
>Y = 0
>for  I = 2 to 6
>   C = asc(substr(S,I,1))
>   Y = (Y * 10 + bitrshift(C,4)) * 10 + bitand(C,255)
>endfor
>Y = Y / 100
>if  left(S,1) = chr(01)
>   Y = - Y
>endif
>There may be a more elegant solution, but that one should work for brute force.
>
>...Jim
>Long-standing member of BPA (Bit Pickers Anonymous)



That looks good Jim. Good to find a memner of BPA as I do not have a need for Nibbles n'Bits too often {g}

Thanks


Alex Feldstein, MCP, Microsoft MVP
VFP Tips: English - Spanish
Website - Blog - Photo Gallery


"Once again, we come to the Holiday Season, a deeply religious time that each of us observes, in his own way, by going to the mall of his choice." -- Dave Barry
Previous
Reply
Map
View

Click here to load this message in the networking platform