Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Subtract 2 hexadecimal numbers

by sundialsvc4 (Abbot)
on Feb 21, 2014 at 15:07 UTC ( #1075738=note: print w/replies, xml ) Need Help??

in reply to Subtract 2 hexadecimal numbers

That would be the devil of a piece of homework ... it could be a real business requirement.   And, in any case, it ought to be comparatively simple as “an exercise for the reader / student.”

In any case, you merely need to read the file two lines at a time ... of course, die() if there is no second-line available.   Yes, that means two read-statements ... one driving the while loop, and the second one within it.   Then in this case you can simply split() each line on the equal-sign character.   Presumably you “know” that the second half of the first line will be inst1, and of the second line, inst2, but once again I think that you should check, and die() if this is not so.   (Pragmatically speaking, only your program will be in a position to detect errors in its input file, and if there is an error in it, don’t let it go undetected and also don’t let it be blamed on you!   If your program runs to completion, it should be an affirmation that the file appears to be correct.)

The final bit of magic is handled by the hex() function, as documented in perldoc -f hex, which will convert your hex-string into an integer.   Do this for each of the two hex-strings that you now have in your hand, and print out the difference.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1075738]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2018-05-27 19:52 GMT
Find Nodes?
    Voting Booth?