The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-14-2006
Registered User
 

Join Date: Sep 2005
Posts: 128
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.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-14-2006
Registered User
 

Join Date: Mar 2006
Location: South Yorkshire, UK
Posts: 114
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
hope this helps

cheers
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 06:27 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0