Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert one byte Hex to numeric

Status
Not open for further replies.

Avalokit

Programmer
Sep 2, 2009
3
US
Hello,

I hate to admit this but I am struggling a bit here.

I am working with a file that contains a one byte field in binary (i.e. hex) that I need to convert to numeric. To be more specific I have an example; the one byte field in hex comes in as an '80', which in turn should translate to '128'. But I haven't been able to accomplish this ... I know there is a way but can't seem to figure this out.

Ex.

?
-
8
0

I need to develop a way to take this one byte '80' and convert it to the numeric equivalent of 128. I am using '80' but it could be any value that that one byte could contain.

If anyone could help; I would be eternally grateful.

Regards
 
Have a look at USAGE IS COMPUTIONAL-5 in your manual.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I'm not sure any COBOL I've run across implicitly or explicitly supports 1 byte numbers since the minimum I've seen is 2 byte numbers in the implementations I've run into.

So you have to redefine things, to get where you're wanting to go. Something like (untested b/c no compiler where I'm at now):

Code:
01  Input-Hex         PIC X.

01  Filter-data.
    04  FILTER-NUM    pic S9(4) Binary.
    04  filter-text redefines filter-num.
        08  filler    pic x value low-values.
        08  last-num  pic x.

01  output-number     pic zzz9.

MOVE INPUT-HEX to LAST-NUM.
move filter-num to output-number.
display output-number.

Hope that helps at least get you into the ballpark for a solution.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy
 
Both Micro Focus and FUjitsU COBOL support 1-byte binary fields. Glenn's solution is the one I had to use back in the 60's, but not any more. With Micro Focus COBOL, you can use COMP, COMP-4, COMP-5, or COMP-X. Since the difference in the various COMPs is in the order of bytes, a 1-byte field would be identical for all four formats.

With Micro Focus COBOL, the COMP directive must be turned on to use 1-byte binary fields. I'm not sure what the default is.
 
I'll have to try it with the Fujitsu compiler I have (3.0) to see whether you can do it, but all the other stuff I've worked with didn't. The OP didn't identify what they were working with in the post, but hopefully all the bases are covered.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy
 
NOTE To Glenn9999.

The code works like a champ .... I am very grateful.

If you're close by in Wilmington Delaware .... drinks on me the whole night.

Thanks a ton ... man ... much appreciated.

Now I am going to study the solution so that I can clearly understand.

Frank
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top