![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Rules & FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| conversion | infyanurag | Shell Programming and Scripting | 3 | 06-01-2008 10:04 PM |
| .xls to .csv conversion | neil546 | Shell Programming and Scripting | 7 | 07-17-2007 12:55 AM |
| Hex Conversion | insania | Shell Programming and Scripting | 2 | 03-20-2007 11:15 AM |
| String Conversion in awk | rohanrege | Shell Programming and Scripting | 3 | 02-14-2005 01:05 PM |
| X.25 to TCP/IP conversion | manjunath | IP Networking | 2 | 08-20-2002 05:57 AM |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
conversion
Dear friends,
i am writing sh shell script I have a file containing binary data. like this. 010101010101010101101010101010100001010101010101001. i want to read some particular bits and convert it into decimal valuse. example. 1.first i want to read 5 bits and convert it into decimal. 2. next i have to take from 6 bit to 12 bit ie 6 bits in to decimal value. how it is possible in unix. please provide code. thanks in advance. |
| Forum Sponsor | ||
|
|
|
|||
|
You don't say how you choose which parts of the binary data to convert, so I've put in some code to get start position and length (replace this with your real selection criteria) and pipe the result through bc (which handles preposterously long numbers) to do the actual conversion:
Code:
data="010101010101010101101010101010100001010101010101001" while : do read s?"Start bit (1..n): " read l?"Length : " x=$(expr substr $data $s $l) r=$(print "ibase=2;obase=A; $x" | bc) print Result $r print "Press ^C to quit" done cheers |
|||
| Google UNIX.COM |
| Thread Tools | |
| Display Modes | |
|
|