From: mike@... (Mike Stok) Date: 2003-12-14T04:57:07+09:00 Subject: Re: .unpack("B*") In article , Boris \"BXS\" Schulz wrote: >Hi, > >I have a problem with "unpack". >When I try to unpack a string, I can easily adress the individual chars >via the array. >But when I try to extract the binary values of a string, this does not >work anymore. I can neither adress individual binary digits, nor the 8 >bits corresponding to a char. >Is this a feature or a bug ? And what can I do to adress the bits >individually ? Further, how do I get the binary values of an integer ? > >char = "ABCDE" >myint = char.unpack("B*") >puts myint >> 0100000101000010010000110100010001000101 >puts myint[3] >> nil unpack returns an Array: irb --simple-prompt >> char = "ABCDE" => "ABCDE" >> myint = char.unpack("B*") => ["0100000101000010010000110100010001000101"] >> puts myint[0][3 .. 3] 0 => nil >> puts myint[0][3] 48 => nil >> myint = *char.unpack("B*") => "0100000101000010010000110100010001000101" Hope this helps, Mike -- mike@stok.co.uk | The "`Stok' disclaimers" apply. http://www.stok.co.uk/~mike/ | GPG PGP Key 1024D/059913DA mike@exegenix.com | Fingerprint 0570 71CD 6790 7C28 3D60 http://www.exegenix.com/ | 75D2 9EC4 C1C0 0599 13DA