Apr 2, 2011

Linux Shell Programming: Converting hex to binary

What about:
  • You have to convert a hex value into a binary value
  • Your only tool is a linux shell
  • You have to start in 30s
  • You have to do it for >10000 hex values
Write a small program in c or java or whatever you would prefer?

What about this:
schroff@hades:$ echo "ibase=16;obase=2; 10 "|bc
10000
schroff@hades:$ echo "ibase=16;obase=2; 1F "|bc
11111
ibase: base of input value
obase: base of output value
The following bases can be used:
  • 16 -> hex
  • 10 -> decimal
  •  8 -> octal
  •  2 -> binary

No comments:

Post a Comment