How the @,x,X directives work with Ruby pack()/unpack() method?
I just went through the Ruby Doc . But there is no sufficient code to understand how the below three are used in Real life programming: @ , X , x . can anyone explain it with a simple snippet? Thanks I will give you few example and will be learning together with you: [1,2,3,4].pack("CCCC") => "\x01\x02\x03\x04" So serializes in unsigned chars. Every letter in new byte. [1,2,3,4].pack("CCXCC") => "\x01\x03\x04" [1,2,3,4].pack("CCXXC") => "\x03" Think of the 'X' as backspace directive [1,2,3,4].pack("CCxC") => "\x01\x02\x00\x03" [1,2,3,4].pack("CCxxC") => "\x01\x02\x00\x00\x03" 'x' places zero