×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Convert one byte Hex to numeric

Convert one byte Hex to numeric

Convert one byte Hex to numeric

(OP)
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
   

RE: Convert one byte Hex to numeric

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"

RE: Convert one byte Hex to numeric

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.

RE: Convert one byte Hex to numeric

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"

RE: Convert one byte Hex to numeric

(OP)
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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close