| |||||||||||
Extracting bit-fields from binary Posted by Alok (Alok), 10 February 2007 Hi,I need to extract bit fields from a 32-bit binary number, re-arrange them and form another 32-bit binary bumber. Could you please suggest how to do it ? I don't really know how to apply binary scan/format for this. Thanks, Alok Posted by admin (Graham Ellis), 11 February 2007 Everything is held as a string in Tcl, so that includes yor incoming and outgoing number. Here's a sample that extracts a 4 byte integer from a variable and returns its numebric value.Code:
Not your solution exactly, I know. Can you give me an an exacmple of the incoming string and result you want and I'll see if I can come up with a more tuned answer. Posted by Alok (Alok), 11 February 2007 Hi Graham,Here is an example of what I need : Incoming number : 1000_0010_0000_10101_1000_0010_0000_10101 (32 bits) "_" is just placed to make it readable in this discussion. I need to extract the following : bit_31=1 bit_28_downto_24=00010 bit_23_downto_0=0000_10101_1000_0010_0000_10101 output (32 bits) =concat{bit_31 bit_23_downto_0 bit_28_downto_24 "00"} I have been trying to understand usage of binary scan with ooption 'b'. However its usage, outcoming pattern of bits and the need of having a byte to scan .... difficult to understand and apply it. Thanks & regards, Alok Posted by Alok (Alok), 11 February 2007 Hi,I could do it using string index and string-range operators. Was rather easy ... Thanks. Regards, Alok Posted by admin (Graham Ellis), 12 February 2007 Ah - so it was a string of 0-s and 1-s rather than a packed binary This page is a thread posted to the opentalk forum
at www.opentalk.org.uk and
archived here for reference. To jump to the archive index please
follow this link.
|
| ||||||||||
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho |