perl binary to decimal and hex

Discussion in 'Programming/Scripts' started by rini90, Apr 15, 2009.

  1. rini90

    rini90 New Member

    Hi everybody,

    i have a problem, i have to write a perl script to translate binar numbers to decimal and hex and the same back.

    All I know is, that i have to use Operators like OR, XOR, AND, NOR... also mod, switch
    It isn't allowed to use pack and sprintf.

    Well the problem is, that i have no programming skills.

    I know that e.g. Hex 1A2 is in Decimal 418 because i have to calulate like that
    2x1 = 2
    + 10x16= 160
    + 1x256= 256
    -----------------------
    418

    Decimal in binar e.g. Dec 40 = 101000 because

    40/2 =20 left 0
    20/2 =10 left 0
    10/2= 5 left 0
    5/2 =2 left 1
    2/2 =1 left 0
    1/2 =0 left 1
    ------------------------------
    101000

    and i also know that bin. in dec is e.g.bin 1010 is dec10 because

    1x1² =1
    + 0x2²= 0
    + 1x3²= 9
    + 0x4² =0
    ------------------
    10

    So but know i don't know how to write an Perl script with all these infos . :confused:

    Please help

    Thx

    rini
     
    Last edited: Apr 15, 2009
  2. vernond

    vernond New Member

Share This Page