in reply to Re: printing hexadecimal without printf
in thread printing hexadecimal without printf

I'm not sure I understand that, but my guess is that you don't.

You code does spit out the appropriate decimal values...

  1. 33
  2. 45
  3. 57
  4. 69
  5. ...
and, as line 100, 1221
...so, as I understand your inital question and followup, your issue is presentation or formatting; not the arithmetic, nor any error in the syntax you've shown us (note, however, that your loop is not particularly perlish).

updateFollowing up on (well, preceding up on ???) toolic's suggestion with an example using pack/unpack:

for (my $i = 1; $i <= 20; $i++) { $a+=0x0C; $out = pack "c", $a; $hex = unpack "H2", $out; print "\t$i Now, \$a (as decimal) is:\t$a \tand as hex: 0x$hex\n"; }

And if this is indeed homework, the implicit suggestion of Fletch's comment may be "FGS, at least label it as such."

Replies are listed 'Best First'.
Re^3: printing hexadecimal without printf
by tpais (Novice) on Nov 28, 2007 at 11:41 UTC
    Thank you, your last comment did help very well.