On Tuesday 04 December 2007 07:55, IJALAB wrote: > > hello all, Hello,
> i m new to perl. Do you know C? > i need to decode some bits and represent accordingly back in hex. > > for example: > 0x00002017 is the data, i need to convert the whole value to binary > and see the bit status (for instance if bit 5 is set), $ perl -le' my $x = 0x00002017; print "Bit 5 is ", $x & 0x10 ? "" : "not ", "set"; ' Bit 5 is set $ perl -le' my $x = 0x00002027; print "Bit 5 is ", $x & 0x10 ? "" : "not ", "set"; ' Bit 5 is not set > then start > constructing the binary output value (set bit 3 in a 32-bit binary) > and repeat till the full binary input string is complete and decode > the output to hex and print. > > i could make out the logic but dont know if i can do the following > steps in perl. > 1. after doing a hex2bin conversion to 32-bit can i right shift by > one bit and then check the bit positions and accordingly OR it with a > temporary string one by one to make the output value. Can you explain further what you mean by "binary output", "binary input string", "decode the output to hex" and "hex2bin conversion". What does the input data look like? What kind of conversion do you want to perform on it? What should the output data look like? John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/