Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1075738]
help
Chatterbox?
[virtualsue]: 1nickt thatch repair just finishing
[virtualsue]: they've done enough to get it through winter
holli loves lightning talks
[1nickt]: ... but not the last straw?
1nickt ducks

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (8)
As of 2017-11-21 12:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (299 votes). Check out past polls.

    Notices?