From: nobu.nokada@... Date: 2003-02-17T08:56:20+09:00 Subject: Re: C-like cast from String to Integer needed. Hi, At Mon, 17 Feb 2003 08:23:48 +0900, Michael Bruschkewitz wrote: > I read some data from, for example, Tcp. > These data are read into a String. > Somewhere in these String are 4 bytes, which are the binary > representation of an Integer. > I hope there is a faster, native, solution than: > i = (((s[ofs+0]*256)+s[ofs+1])*256+s[ofs+2])*256+s[ofs+3] > ... but I don't see this. s.unpack("@#{ofs}N") > In C++, it would look somehow like this: > char s[1024]; recv(so,s,sizeof s, 0); // this line not interesting > int y = *(int*)(s+ofs); // this line needed in Ruby. Note that it's not portable. -- Nobu Nakada