[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

reading unsigned byte

warhero

3/7/2007 3:45:00 PM

I'm experiencing unexpected behavior when reading an byte.. as apposed
to PHP which is returning expected results.

this is how I'm reading the byte in ruby: int =
somedata.unpack('c').first

the result I'm getting in ruby is -127. In php I get 128. This is how I
read it in php:

int = ord(@this->raw_data($this->current_byte++]);

not sure how to go about debugging this..
thanks

--
Posted via http://www.ruby-....

3 Answers

Dale Martenson

3/7/2007 4:00:00 PM

0

On Mar 7, 9:44 am, warhero <beingthexemplaryli...@gmail.com> wrote:
> I'm experiencing unexpected behavior when reading an byte.. as apposed
> to PHP which is returning expected results.
>
> this is how I'm reading the byte in ruby: int =
> somedata.unpack('c').first
>
> the result I'm getting in ruby is -127. In php I get 128. This is how I
> read it in php:
>
> int = ord(@this->raw_data($this->current_byte++]);
>
> not sure how to go about debugging this..

'c' extracts a signed integer. 'C' extracts an unsigned integer.

irb(main):002:0> "\x80".unpack('c').first
=> -128
irb(main):003:0> "\x80".unpack('C').first
=> 128

warhero

3/7/2007 4:21:00 PM

0

Dale Martenson wrote:
> On Mar 7, 9:44 am, warhero <beingthexemplaryli...@gmail.com> wrote:
>>
>> not sure how to go about debugging this..
>
> 'c' extracts a signed integer. 'C' extracts an unsigned integer.
>
> irb(main):002:0> "\x80".unpack('c').first
> => -128
> irb(main):003:0> "\x80".unpack('C').first
> => 128

Ha, Duh, as soon as you posted this I caught that in the docs. Thanks.


--
Posted via http://www.ruby-....

The Peeler

3/31/2013 3:46:00 PM

0

On Sun, 31 Mar 2013 08:18:28 -0700 (PDT), NEMO wrote:

> The squarehead wife - beating Dutchman Heinrich goes insane again, "
> fuck yoou. i am angry already because it has started to snow again.
> this is driving me crazy!"
>
> ....& he'll probably start beating his wife again!
>
> . Sounds like your usual squarehead wife - beating Dutchman!
>
> Fuck 'em!

I suppose his all alone again, his "family" is out having a good time
without him, all he can do is swallow yet more pills! LOL