in reply to Converting Binary to hex

Hi Himaja,

your $binadddr variable is assigned to a decimal integer, not to a binary integer.

If you expect $binaddr to be a binary integer, then you should use:

$binadddr = 0B100010

Replies are listed 'Best First'.
Re^2: Converting Binary to hex
by Himaja (Novice) on Sep 30, 2016 at 06:15 UTC

    actually $binaddr is read from a hash. so the value is something like initialvalue = '0100010' which i read into $binaddr. So i am appending 0b while passing it to hex function. Looks like the format of the data extracted from the hash cannot be directly sent to hex function. Any idea?

      Hmm, I can't test right now, but the 0B prefix will work, I think, only for an initial numerical literal assignment. Once the value is in memory, you can no longer do it his way and you probably need to make an explicit conversion from binary string to whatever you need.