looking for a program

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: KevinBuettnerkev@primenet.com
Date:  
Subject: looking for a program
On Feb 6, 6:03pm, Lucas Vogel wrote:

> I'm looking for a program that will take either a decimal, hex or octal
> input and give me its decimal, hex or octal output. Can anyone tell me what
> I'm looking for?


Like others who've answered, the first thing I thought of was
Perl...

    saguaro:kev$ perl -e 'printf "%x\n", 42'
    2a
    saguaro:kev$ perl -e 'printf "%d\n", 0x2a'
    42
    saguaro:kev$ perl -e 'printf "%o\n", 0x2a'
    52
    saguaro:kev$ perl -e 'printf "%d\n", 052'
    42


But gdb works good for this purpose too...

    saguaro:kev$ gdb
    GNU gdb 5.0
    [...]
    (gdb) print/x 42
    $1 = 0x2a
    (gdb) print 0x2a
    $2 = 42
    (gdb) print/o 0x2a
    $3 = 052
    (gdb) print 052
    $4 = 42
    (gdb) 


gdb makes a pretty good calculator too...

    (gdb) print/x 6*7
    $5 = 0x2a
    (gdb) print $5/7  
    $6 = 6
    (gdb) print $5+$6
    $7 = 48


And for you C/C++ programmers out there...

    (gdb) print &((int *) 0)[4]
    $8 = (int *) 0x10
    (gdb) print/d &((int *) 0)[4]
    $9 = 16


(This'd be the byte offset of the fourth element in an int array. Of
course, the results are target dependent.)

Kevin