Proxmark3 developers community

Research, development and trades concerning the powerful Proxmark3 device.

Remember; sharing is caring. Bring something back to the community.


"Learn the tools of the trade the hard way." +Fravia

You are not logged in.

#1 2015-07-31 13:39:58

rbubba1911
Contributor
Registered: 2014-08-14
Posts: 86

light linux utility to convert number

Hi,

I doesn't found a tool to manipulate long binary string (or hex) so I define some alias
you need to have bc installed.


create a file binconv.sh  with the following

function bin2hex() {
  echo "ibase=2;obase=10000;$1" | bc
}

function dec2hex() {
  echo "ibase=10;obase=16;$1" | bc
}

function hex2bin() {
  STR=echo $1 | tr '[a-f]' '[A-F]'
  echo "ibase=16;obase=2;$STR" | bc
}

function hex2dec() {
  STR=echo $1 | tr '[a-f]' '[A-F]'
  echo "ibase=16;obase=A;$STR" | bc
}

function hex2str() {
  I=0
  STR=$1
  while [ $I -lt ${#STR} ];
  do
    echo -en "\x"${STR:$I:2}
    let "I += 2"
  done
}

alias bin2hex=bin2hex
alias hex2bin=hex2bin
alias dec2hex=dec2hex
alias hex2dec=hex2dec
alias hex2str=hex2str


then source the file
   . binconv.sh

now, you can use converter like this

like :
bin2hex 11111111111110100001110000000000111110011010100010101010111100100100110111000000101000010001001011111000110000100001000000000110
FFFA1C00F9A8AAF24DC0A112F8C21006


hex2bin FFFA1C00F9A8AAF24DC0A112F8C21006
11111111111110100001110000000000111110011010100010101010111100100100110111000000101000010001001011111000110000100001000000000110

update: add case convert and output to str

Have a nice day

Last edited by rbubba1911 (2015-08-01 23:07:32)


Double the trouble, Twice the fun !!

Offline

#2 2015-07-31 15:05:27

iceman
Administrator
Registered: 2013-04-25
Posts: 6,537
Website

Re: light linux utility to convert number

We should really build this kind of functionality into the client...


If you feel the love,  https://www.patreon.com/iceman1001

modhex(hkhehghthbhudcfcdchkigiehgduiehg)

Online

#3 2015-07-31 23:09:34

holiman
Contributor
Registered: 2013-05-03
Posts: 566

Re: light linux utility to convert number

Coming right up...

proxmark3> data hex2bin deadbeef
11011110101011011011111011101111
proxmark3> data bin2hex 11011110101011011011111011101111
DEADBEEF
proxmark3> data bin2hex 1
[padded with 7 zeroes]
80
proxmark3> 

Offline

#4 2015-07-31 23:15:04

iceman
Administrator
Registered: 2013-04-25
Posts: 6,537
Website

Re: light linux utility to convert number

big_smile

however,   Bin 1 -> hex 80 ?!?!    I still thought that would be 01... wink


If you feel the love,  https://www.patreon.com/iceman1001

modhex(hkhehghthbhudcfcdchkigiehgduiehg)

Online

#5 2015-07-31 23:21:31

holiman
Contributor
Registered: 2013-05-03
Posts: 566

Re: light linux utility to convert number

Hm. I didn't even consider that, it felt intuitive that zeroes were added to the right side. I saw it as a "stream of data", not as a "value". If you use it to convert "values", I understand that it feels counter-intuitive...

I would probably only use this function to convert large blobs of binary. If you have a really big blob, it feels strange that the first byte of output differs depending on if you cut'n'pasted 1023 digits instead of 1024....

Offline

#6 2015-07-31 23:30:24

iceman
Administrator
Registered: 2013-04-25
Posts: 6,537
Website

Re: light linux utility to convert number

I guess I've been cut 'n pasting from the calc too many times,  where it takes away the leftmost zeros.  Always forcing me to start in the rightmost position and figuring out how much to pad when I gone thru all numerals


If you feel the love,  https://www.patreon.com/iceman1001

modhex(hkhehghthbhudcfcdchkigiehgduiehg)

Online

Board footer

Powered by FluxBB