in reply to printing hexadecimal without printf

hi ww, well, that's true :-) this line: $a+=0x0C is not working, because it count decimal. or am i mistaken ?
  • Comment on Re: printing hexadecimal without printf

Replies are listed 'Best First'.
Re^2: printing hexadecimal without printf
by ww (Archbishop) on Nov 26, 2007 at 14:13 UTC
    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."

      Thank you, your last comment did help very well.