From: mike@... (Mike Stok) Date: 2003-12-14T12:26:58+09:00 Subject: Re: .unpack("B*") In article , Boris \"BXS\" Schulz wrote: >And what can I do to adress the bits >individually ? Further, how do I get the binary values of an integer ? I don't quite understand what this means, but 'ABCDE'.each_byte do |b| 0.upto(7) do |bit| print "(#{b[bit]})" end print "\n" end prints (1)(0)(0)(0)(0)(0)(1)(0) (0)(1)(0)(0)(0)(0)(1)(0) (1)(1)(0)(0)(0)(0)(1)(0) (0)(0)(1)(0)(0)(0)(1)(0) (1)(0)(1)(0)(0)(0)(1)(0) where Fixnum#[] is used to access the bits of each byte -------------------------------------------------------------- Fixnum#[] fix[ n ] -> 0, 1 ------------------------------------------------------------------------ Bit Reference---Returns the nth bit in the binary representation of fix, where fix[0] is the least significant bit. a = 0b11001100101010 30.downto(0) do |n| print a[n] end produces: 0000000000000000011001100101010 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