How Does Ruby handle bytes/binary?

前端 未结 3 1347
日久生厌
日久生厌 2021-02-05 17:56

I\'m trying to send a series of binary bytes across a socket, to meet a particular standard my company uses. No one in my company has used Ruby for this before, but in other lan

3条回答
  •  温柔的废话
    2021-02-05 18:52

    Have a look at the String.unpack method. This is an example:

    str = "1010"
    str.unpack("cccc")
    => [49, 48, 49, 48]
    

    This will give you integer values. There are more ways to do the conversion.

提交回复
热议问题