Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
32 ビット整数をネットワーク バイト オーダーに変換する方法。
それを行う正しい方法は何ですか?
[1024].pack("N")
また
[1,0,2,4].pack("N")
ありがとう
まず、それぞれの出力を見てください。
>> [1024].pack("N") => "\000\000\004\000" >> [1,0,2,4].pack("N") => "\000\000\000\001"
2番目に欠けているものに注意してください:
>> [1,0,2,4].pack("NNNN") => "\000\000\000\001\000\000\000\000\000\000\000\002\000\000\000\004"