From: Sung Pae Date: 2012-08-01T10:44:34+09:00 Subject: Re: working with large binary strings? bob hope writes: > I need to work with multiple large binary strings, and to do XOR > operations on their 'rows'. This is all fine, but I am having a slow > time to get binary representation in this fashion: > > a = SecureRandom.random_bytes(250_000).unpack("B*")[0].to_i.to_s(2) You are asking ruby to convert a string into a _number_ 250,000 places wide, then asking to convert this very large base-10 number into a string using radix 2. > I know there must be a quick way to do it, because a = > SecureRandom.random_bytes(250_000) is very fast, so I don't know why > it would be slow to convert that into a bit string of 1's and 0's SecureRandom.random_bytes(250_000).unpack("B*") returns a random string of 1's and 0's > that will allow me to manipulate it on a bit by bit basis. Is there a > faster way to do this? Generating that string takes about one second, > but then getting its binary form as 1's and 0's takes a few minutes. If you need fast bitwise operations, why are you using strings? guns