All pastes #374133 Raw Edit

Anonymous

public text v1 · immutable
#374133 ·published 2007-02-27 09:05 UTC
rendered paste body
* hello is a file with the word hello in it or you can  just substitute cat hello with " echo hello  "

to convert ascii to hex do :

agiofws@celeron3~
$cat hello | xxd -p
68656c6c6f0a

$cat hello | xxd -p -i  
  0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x0a 

$cat hello | xxd -p -i -c 1
  0x68,---->h
  0x65,---->e
  0x6c,---->l
  0x6c,---->l
  0x6f,---->o
  0x0a,---->.

you can use "xev" to  proove the keycodes are right 

to convert ascii to binary digits you can  do 

cat hello | xxd -b  -c 1
0000000: 01101000  h            0x68,---->h
0000001: 01100101  e 		0x65,---->e
0000002: 01101100  l 		0x6c,---->l
0000003: 01101100  l 		0x6c,---->l
0000004: 01101111  o 		0x6f,---->o
0000005: 00001010  . 		0x0a,---->.


to convert from Hex to ascii do 

$echo  hello   | xxd  -p
68656c6c6f0a


$echo 68656c6c6f0a  | xxd  -p -r 
hello

or 

agiofws@celeron3~
$echo 68 65 6c 6c 6f 0a  | xxd  -p -r 
hello


or 

because this converts hex to ascii perfectly fine:

declare -i n=0xFF; printf '%s' $n


to convert from std input to binary digits 

read a ; echo $a  | xxd -b | cut -c 10-64



agiofws@celeron3~
$ declare -i n=2#1011; printf "dec: %d, oct: %o, hex: %x\n"  $n $n $n
dec: 11, oct: 13, hex: b



binary=$(echo "obase=16 ; ibase=2 ;1011" | bc ) ; echo $binary

var=$(read a ; echo $a  | xxd -b | cut -c 10-64 | tr -d '[[:space:]]'  | sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{8\}\)/\1.\2/;ta')


read a   ; declare -i n=2#$a ; printf "%x\n" $n | xxd  -p -r

bonsai@mainserver:~/sources$ IFS=. read -a test <<<"a.b.c.d.e.f"
TheBonsai bonsai@mainserver:~/sources$ set | grep ^test
TheBonsai test=([0]="a" [1]="b" [2]="c" [3]="d" [4]="e" [5]="f")
TheBonsai bonsai@mainserver:~/sources$
* mwilson has quit ("Leaving")
TheBonsai bonsai@mainserver:~/sources$ var=a.b.c.d.e.f; test2=(${var//./ }); set | grep ^test2
TheBonsai test2=([0]="a" [1]="b" [2]="c" [3]="d" [4]="e" [5]="f")
TheBonsai bonsai@mainserver:~/sources$ var=a.b.c.d.e.f; set -- ${var//./ }; echo "$@"
TheBonsai a b c d e f

for i in `seq  32` ; do echo ${var2[$i]} ; done 

$for i in `seq 32` ; do  declare -i n=2#${var2[$i]} ; printf "%x\n" $n | xxd  -p -r ; done

 
read a; ccount=${#a}; var=$(xxd -b <<<"$a" | cut -c 10-64 | tr -d '[[:space:]]' ....); echo $count




clear ;var=$(read a ; echo $a | xxd -b | cut -c 10-64 | tr -d '[[:space:]]'  |  sed -e :a -e 's/\(.*[0-1]\)\([0-1]\{8\}\)/\1.\2/;ta') ; var2=(${var//./ });  for i in {0..5000} ; do   declare -i n=2#${var2[$i]} ; printf "%x\n" $n | xxd  -p -r ; done




clear ; echo "please paste you ascii text here" ; var=$(read a ; echo $a | xxd -b | cut -c 10-64 | tr -d '[[:space:]]'  |  sed -e :a -e 's/\(.*[0-1]\)\([0-1]\{8\}\)/\1.\2/;ta')



clear ; echo "please paste your binary text here " ; read b ; b=(${var//./ }) ; for i in {0..5000}  ; do   declare -i n=2#${b[$i]} ; printf "%x\n" $n | xxd  -p -r ; done



01101101.01101111.01101110.01101111.00100000.01100101.01101110.01100001.00100000.01100100.01101001.01110011.01110100.01110010.01101111.00100000.01111001.01110000.01100001.01110010.01111000.01100101.01101001.00001010