in reply to Perl hex substraction

Nice problem! I will add this to my list of exercises I use when teaching programming...

I assume your current lesson is loops. Which kind did you already learn about? (It would be too embarrassing if we would advise you some syntax which your instructor didn't already cover, wouldn't it?).

The arithmetic shouldn't be a problem at all ... remember the hex-function?

Thinking twice, it would probably best if you just show us the code you have already written - and where you have doubts... that way we could help you best, without wasting your (and our) time ...

Have fun learning!

Rata

Replies are listed 'Best First'.
Re^2: Perl hex substraction
by raybies (Chaplain) on Feb 15, 2011 at 13:15 UTC

    It is kind of a fun problem, because on the surface the student may think he/she needs to implement a whole new form of subtraction for hex numbers... rather than doing the easy thing which is to convert a hex string to a value, and then just print out the result as a hex value. I can see students learing something like operator overloading in a C++ class getting really wrapped around something like this, trying to create a whole new form of subtraction... in Perl, not nearly the same temptation and underscores the importance of referencing strings as values when you need values, and strings when you need strings.

    Then again I remember in an earlier EE course, we were supposed to know how to do hexadecimal subtraction, when we were learning different number bases, longhand... which isn't that tough, especially if you can use 2's complement binary lookups.