From: arton Date: 2008-09-07T14:48:54+09:00 Subject: Re: how to change ASCI to Hex --------------------------------- Joel VanderWerf vjoel@path.berkeley.edu vjoel@path.berkeley.edu, ruby-talk@ruby-lang.org (ruby-talk ML) how to change ASCI to Hex > arton wrote: > > --------------------------------- Joel VanderWerf vjoel@path.berkeley.edu > > vjoel@path.berkeley.edu, ruby-talk@ruby-lang.org (ruby-talk ML) > > how to change ASCI to Hex > >> Zqd Zqd wrote: > >>> hi everyone: > >>> I want to change ASCI to Hex,which i receive in the UDPSocket,but it > >>> just report error > >>> > >>> 1) my code is: > >>> server = UDPSocket.open > >>> server.bind('192.168.203.108', $port) > >>> s= server.recvfrom(164) > >> I think this is what you're asking for: > >> > >> s.unpack("C")[0] > >> > >> -- > >> vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407 > > > > Joel, In Ruby 1.9 you're right, but with Ruby 1.8 no need to unpack, > > because str[n] returns just one character at the index points > > > > Then, > > server = UDPSocket.open > > server.bind('192.168.203.108', $port) > > s= server.recvfrom(164) > > s=s[0] > > p s > > True, but that's what the OP tried and got an error. Perhaps OP's ruby > is 1.9? > > Anyway, I'm guessing the next question will be "how do I get a long from > positions 3..7?", and so might as well get started using unpack.... you may see the version invoking ruby with -v option ie) c:\>ruby -v ruby 1.9.0 (2008-08-26 revision 18849) [i386-mswin32] > I'm guessing the next question will be "how do I get a long from > positions 3..7?", and so might as well get started using unpack.. Um, you are correct. I respect you. -------------------------------------- Enjoy MLB with MAJOR.JP! Ichiro, Matsuzaka, Matsui, and more! http://pr.mail.yahoo.co.jp/mlb/