[OSM-dev] Ruby help - streams of bits

SteveC steve at asklater.com
Thu May 17 14:58:13 BST 2007


On 17 May 2007, at 14:51, SteveC wrote:

>
> 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

c = []

> first = false

count = 0

> a.each do |n|
>    a = a << 1 if first
>    a += n
>    first = false
  if count == 8
  c << a
a = count = 0
end
# and stuff
> end



>
>
>
> have fun,
>
> SteveC | steve at asklater.com | http://www.asklater.com/steve/
>
>
>
> _______________________________________________
> dev mailing list
> dev at openstreetmap.org
> http://lists.openstreetmap.org/cgi-bin/mailman/listinfo/dev
>

have fun,

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






More information about the dev mailing list