Need some python help (or maybe C )

Bill Campbell linux-sxs at celestial.com
Sat Dec 13 21:35:21 PST 2008


On Sat, Dec 13, 2008, Ben Duncan wrote:
>
> I have a hex value as x'000123456D". It is a COMP-3 (Binary coded decimal)
> for a cobol program. That says to me and is in actuality the number 123456-,
> The LAST nibble D is negative and F or C would be postive.
>
> I need to get this to a "integer" or a string.

I would use the python struct module to break out the invidiual digits
(Burroughs speak for the cutesy nibbles of IBM :-) of this.  It will take a
bit of fiddling to split the bytes into digits.  Split it into bytes, the
AND out the left and right halves of the byte, something like:

leftmask = 0xF0
rightmask = 0x0F
leftdigit = (byte & leftmask) >> 4
rightdigit = byte & rightmask

Bill
-- 
INTERNET:   bill at celestial.com  Bill Campbell; Celestial Software LLC
URL: http://www.celestial.com/  PO Box 820; 6641 E. Mercer Way
Voice:          (206) 236-1676  Mercer Island, WA 98040-0820
Fax:            (206) 232-9186

The day-to-day travails of the IBM programmer are so amusing to most of
us who are fortunate enough never to have been one -- like watching
Charlie Chaplin trying to cook a shoe.



More information about the Linux-users mailing list