From: "Simon Kröger" Date: 2005-09-01T05:10:03+09:00 Subject: Re: how to convert binary array into integer Zach Dennis wrote: > Joe Van Dyk wrote: > >> On 8/31/05, hsun wrote: >> >>> Hi, >>> >>> Does anyone know the api to convert a binary array into integer: >>> >>> for example: 00 00 00 0A => 10 >> >> >> >> Have you looked at String#unpack? > > > > "\000\000 A".unpack( "f" ) => 10.0 > > Zach This was a joke, right? "\000\000 B".unpack( "f" ) => 40.0 if not, i didn't want to be cynical. you can try this: a = [0x00,0x00,0x00,0x0A] puts a.inject(0){|r, i| r << 8 | i} cheers Simon