1

I'm trying to build a little GUI with max/msp for a ruby project I can't find a way to properly convert the data i receive form max.

here is several examples of message that i've received from max in ruby (i've send 2 first then 1 0 -1 -2):

["int\x00,i\x00\x00\x00\x00\x00\x02", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\x00\x00\x00\x01", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\x00\x00\x00\x00", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\xFF\xFF\xFF\xFF", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]
["int\x00,i\x00\x00\xFF\xFF\xFF\xFE", ["AF_INET", 53802, "127.0.0.1", "127.0.0.1"]]

so far i've been able to convert positive values to integer via String#ord or String#unpack but with those methods negative integers gives me 0 value

5
  • what's the issue , i am not getting... share your code please. Jun 23, 2013 at 11:11
  • i just want to know how to convert first part of the message ("int\x00,i\x00\x00\xFF\xFF\xFF\xFF") to integer in ruby, do you know how to do that? Jun 23, 2013 at 11:33
  • Is this "int\x00,i\x00\x00\x00\x00\x00\x02".ord # => 105 you want ? Jun 23, 2013 at 11:35
  • no this value should return => 2 Jun 23, 2013 at 11:36
  • the five messages in my question are received when i'm successively send 2, 1, 0, -1, -2 from max/msp. i just want to convert back to integer Jun 23, 2013 at 11:38

1 Answer 1

2

You can easily do it with #unpack, using offset ('@8'), and 32-bit signed bigendian int ('l>')

str.unpack('@8l>')

I'm not sure what initial part of string means ("int\x00,i\x00\x00") and I have just ignored it with offset. It might need additional fiddling, if there is any important data.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.