Rajeev, Actually, i get data in hex bytes from a log file. I have to parse them or analyze them according to some predefined rules or values.
For eg: a hex byte of 0xa4 is converted to binary as 10100100 Now, i have a file in which the values are predefined. It looks like 0xa4 => 10100100 in that MSB 1 stands for some abc then the following bits 01 stands for cdf then the remaining bits 00100 stands for xyz (0/1) | 2 bits | 5 bits abc | System name | Other details System name Other Details 00 ujj 00000 01 cdf 00001 etc.... 10 bbg 11 gtt In the above example, the text is just an eg and not the actual text. I get those 8 bits as a whole as hex byte which i need to parse and diplay them bitwise. Hope this explains better. Dharshana On 11/9/06, kilaru rajeev <[EMAIL PROTECTED]> wrote:
Dharshana, The program you wrote here to convert the number to binary is good. In the second one, I am not getting what is your intention correctly. You said you what to convert 0=> abc,..... Can I know a little bit more. Rajeev On 11/9/06, Dharshana Eswaran <[EMAIL PROTECTED]> wrote: > > Hi all, > > I wanted to know how to parse a 8bit binary data bitwise? > > I have my input in hex and i convert it into binary form using the > following > logic: > > %h2b = (0 => "0000", 1 => "0001", 2 => "0010", 3 => "0011", > 4 => "0100", 5 => "0101", 6 => "0110", 7 => "0111", > 8 => "1000", 9 => "1001", a => "1010", b => "1011", > c => "1100", d => "1101", e => "1110", f => "1111", > ); > > $hex = "43"; > ($binary = $hex) =~ s/(.)/$h2b{lc $1}/g; > print $binary, "\n"; > > Now the output for the above prg is > > 01000011 > > Now i have to display this binary data as shown below: > > 0=> abc > 100=> def > 0011=> lmn > > How to go about this? > >