[OSM-dev] Ruby help - streams of bits

SteveC steve at asklater.com
Thu May 17 14:51:25 BST 2007


On 17 May 2007, at 13:49, Richard Fairhurst wrote:

> SteveC wrote:
>
>> can't you do something like
>>
>> a = ''
>>
>> a[0] = 123
>>
>> to set byte 0 of a string to char 123?
>
> Sure, it's getting from the '01001' '1100111' '0011111' etc. to the  
> bytes that's the slow bit, I think.
>

umm... but why would you do that in the first place?

you could make a byte with

a = 1
a = a << 1
a += 1
a = a << 1  # a==3

etc

or a bit array and then make bytes?

a = []
a << 1
a << 1

b = 0
first = false
a.each do |n|
   a = a << 1 if first
   a += n
   first = false
end



have fun,

SteveC | steve at asklater.com | http://www.asklater.com/steve/






More information about the dev mailing list