{"id":10472,"date":"2026-07-14T23:40:00","date_gmt":"2026-07-14T14:40:00","guid":{"rendered":"http:\/\/hdmr.org\/d\/?p=10472#"},"modified":"2026-07-15T01:40:46","modified_gmt":"2026-07-14T16:40:46","slug":"wp-10472","status":"publish","type":"post","link":"https:\/\/hdmr.org\/d\/wp-10472","title":{"rendered":"\u30d0\u30a4\u30c8\u30aa\u30fc\u30c0\u30fc\u3092\u9078\u3093\u3067unpack"},"content":{"rendered":"<p>\u7c21\u5358\u306a\u30c7\u30fc\u30bf\u5909\u63db\u3092\u884c\u3046\u30b9\u30af\u30ea\u30d7\u30c8\u3092Ruby\u3067\u66f8\u3044\u3066\u3044\u305f\u3002<\/p>\n<p>\u306a\u3093\u3067Ruby\u304b\u3068\u3044\u3046\u3068\u3001\u4ed6\u306e\u76ee\u7684\u3067Ruby\u3092\u4f7f\u3063\u3066\u3044\u308b\u74b0\u5883\u3060\u3063\u305f\u304b\u3089\u3002<\/p>\n<p>\u51e6\u7406\u3092\u66f8\u3044\u3066\u3044\u308b\u4e2d\u3067\u3001\u305d\u3046\u3044\u3048\u3070\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u3092\u6307\u5b9a\u3057\u3066\u6574\u6570\u3068\u30d0\u30a4\u30c8\u5217\u3092\u5f80\u6765\u3059\u308b\u306b\u306f\u3069\u3046\u3059\u308c\u3070\u3088\u3044\u306e\u3060\u308d\u3046\u3068\u3002<\/p>\n<hr>\n<p>Ruby\u3067\u306f\u30d0\u30a4\u30ca\u30ea\u30c7\u30fc\u30bf\u3082\u6587\u5b57\u5217\u3068\u3057\u3066\u6271\u3046\u3088\u3046\u3067\u3059\u306d\u3002<\/p>\n<p>Ruby\u3067\u306f\u6587\u5b57\u5217\u306b\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u60c5\u5831\u304c\u4ed8\u52a0\u3055\u308c\u3066\u3044\u308b\u306e\u3060\u304c\u3001<\/p>\n<p>ASCII-8BIT\u3063\u3066\u306e\u304c\u30d0\u30a4\u30ca\u30ea\u30c7\u30fc\u30bf\u3092\u6271\u3046\u30a8\u30f3\u30b3\u30fc\u30c7\u30a3\u30f3\u30b0\u3060\u3068\u3002<\/p>\n<p>\u6587\u5b57\u5217\u3092\u6570\u5b57\u306e\u914d\u5217\u306b\u5909\u63db\u3059\u308b\u305f\u3081\u306b\u306funpack\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3046\u305d\u3046\u3002<\/p>\n<p>\u305d\u308c\u3067\u30b5\u30f3\u30d7\u30eb\u30b3\u30fc\u30c9\u3092\u898b\u308b\u3068\u3053\u3093\u306a\u3053\u3068\u304c\u66f8\u304b\u308c\u3066\u3044\u305f\u3002<\/p>\n<pre>int_le = bytedata.byteslice(idx,4).unpack(\"L&lt;\")[0]<br>int_be = bytedata.byteslice(idx,4).unpack(\"L&gt;\")[0]<\/pre>\n<p>\u305d\u3082\u305d\u3082pack, unpack\u3068\u3044\u3046\u306e\u304c\u6163\u308c\u306a\u3044\u3068\u3053\u308d\u306f\u3042\u308b\u304c\u3001<\/p>\n<p>&#8220;&lt;&#8220;\u3068\u3044\u3046\u8a18\u53f7\u306f\u4e00\u4f53\u4f55\u3092\u8868\u3057\u3066\u3044\u308b\u306e\u304b\u3068\u6c17\u306b\u306a\u3063\u305f\u3002<\/p>\n<hr>\n<p>pack, unpack\u3063\u3066\u306e\u306fPerl\u306b\u7531\u6765\u3057\u3066\u3044\u308b\u306e\u304b\u306a?<\/p>\n<pre>$text = pack(\"C*\",@byte);<br>@byte = unpack(\"C*\",$text);<\/pre>\n<p>\u306e\u3088\u3046\u306a\u611f\u3058\u3067\u6587\u5b57\u5217$text\u30681byte\u5358\u4f4d\u306e\u914d\u5217@byte\u3092\u5909\u63db\u3059\u308b\u306e\u304c\u5178\u578b\u7684\u306a\u4f7f\u3044\u65b9\u3002<\/p>\n<p>\u305d\u308c\u305e\u308c\u5f15\u6570\u306e&#8221;C&#8221;\u304cunsigned char\u306b\u5bfe\u5fdc\u3059\u308b\u3068\u3044\u3046\u308f\u3051\u3067\u3042\u308b\u3002<\/p>\n<p>\u3053\u3053\u306b\u306f2byte\u4ee5\u4e0a\u306e\u578b\u3082\u3042\u308a\u300132bit\u7b26\u53f7\u7121\u3057\u6574\u6570\u306b\u5bfe\u5fdc\u3059\u308b\u306e\u304c&#8221;L&#8221;\u3067\u3042\u308b\u3002<\/p>\n<p>\u305f\u3060\u3001\u3053\u306e&#8221;L&#8221;\u306f\u30d0\u30a4\u30c8\u30aa\u30fc\u30c0\u30fc\u304c\u74b0\u5883\u4f9d\u5b58\u3067\u3042\u308b\u3002(\u591a\u304f\u306e\u5834\u5408\u306f\u30ea\u30c8\u30eb\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u3068\u8003\u3048\u3089\u308c\u3066\u3044\u308b\u304c)<\/p>\n<p>\u305d\u3053\u3067 &#8220;&lt;&#8220;\u3092\u4ed8\u52a0\u3059\u308b\u3068\u30ea\u30c8\u30eb\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u3001&#8221;&gt;&#8221;\u3092\u4ed8\u52a0\u3059\u308b\u3068\u30d3\u30c3\u30af\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u3068\u6307\u5b9a\u3067\u304d\u308b\u4ed5\u7d44\u307f\u304c\u3042\u308b\u3068\u3002<\/p>\n<hr>\n<p>\u3053\u3046\u3044\u3046\u306e\u3063\u3066Perl\u306b\u3082\u3042\u308b\u306e\u304b\u3068\u8abf\u3079\u305f\u3089\u3042\u308b\u3089\u3057\u3044\u3002<\/p>\n<p>\u3082\u3063\u3068\u3082Perl\u3067\u3082Ruby\u3067\u3082\u305d\u3046\u306a\u306e\u3060\u304c\u3001\u30d3\u30c3\u30af\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u306e32bit\u7b26\u53f7\u7121\u3057\u6574\u6570\u306f &#8220;N&#8221; \u3067\u3082\u8868\u73fe\u3067\u304d\u308b\u305d\u3046\u3002<\/p>\n<p>\u306a\u305c &#8220;N&#8221;\u306a\u306e\u304b\u3068\u3044\u3046\u3068\u30cd\u30c3\u30c8\u30ef\u30fc\u30af\u30d0\u30a4\u30c8\u30aa\u30fc\u30c0\u30fc\u3068\u3044\u3046\u610f\u5473\u3089\u3057\u3044\u3002<\/p>\n<p>\u3053\u3061\u3089\u306e\u65b9\u304cPerl\u3067\u306f\u4e00\u822c\u7684\u306a\u66f8\u304d\u65b9\u306e\u3088\u3046\u3067\u3042\u308b\u3002<\/p>\n<p>\u9006\u306b\u30ea\u30c8\u30eb\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u306e32bit\u6574\u6570\u306f &#8220;V&#8221; \u3068\u66f8\u304f\u305d\u3046\u3002<\/p>\n<hr>\n<p>\u3053\u306e\u3042\u305f\u308a\u306f\u74b0\u5883\u306b\u3088\u308a\u3044\u308d\u3044\u308d\u3042\u308b\u3068\u3044\u3046\u8a71\u3060\u304c\u3002<\/p>\n<p>\u305f\u3060\u3001\u3061\u3087\u3063\u3068\u524d\u306b.NET Framework\u306e\u3053\u306e\u624b\u306e\u51e6\u7406\u306e\u5b9f\u88c5\u4f8b\u3092\u898b\u3066\u9a5a\u3044\u305f\u3093\u3060\u3051\u3069\u2026\u2026<\/p>\n<p><a href=\"https:\/\/learn.microsoft.com\/ja-jp\/dotnet\/api\/system.bitconverter?view=net-10.0\">BitConverter Class (Microsoft Learn)<\/a><\/p>\n<p>\u3053\u306e\u4e2d\u3067\u30d3\u30c3\u30b0\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u306b\u5bfe\u5fdc\u3055\u305b\u308b\u305f\u3081\u306b\u306f\u3069\u3046\u3059\u308b\u304b\u3068\u3044\u3046\u8a71\u3067\u3001<\/p>\n<p>IsLittleEndian\u304ctrue\u306a\u3089\u3070\u3001Array.Reverse\u3067\u30d0\u30a4\u30c8\u5217\u306e\u9806\u756a\u3092\u53cd\u8ee2\u3059\u308b\u51e6\u7406\u3092\u5165\u308c\u308b\u3068\u306a\u3063\u3066\u3044\u308b\u3002<\/p>\n<p>\u679c\u305f\u3057\u3066.NET Framework\u304c\u52d5\u304f\u74b0\u5883\u3067\u30d3\u30c3\u30af\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u304c\u3042\u308b\u306e\u304b\u306f\u7591\u554f\u306a\u306e\u3060\u304c\u3001<\/p>\n<p>\u3053\u308c\u3092\u898b\u3066\u3001\u5b9f\u884c\u74b0\u5883\u306e\u30d0\u30a4\u30c8\u30aa\u30fc\u30c0\u30fc\u3068\u4e0d\u4e00\u81f4\u306a\u3089\u3070\u30d0\u30a4\u30c8\u9806\u3092\u53cd\u8ee2\u3055\u305b\u308b\u3053\u3068\u3067\u5bfe\u5fdc\u3057\u3066\u304f\u308c\u3068\u3044\u3046\u3053\u3068\u3089\u3057\u3044\u3002<\/p>\n<p>\u3082\u3046\u3061\u3087\u3063\u3068\u306a\u3093\u3068\u304b\u306a\u3089\u3093\u306e\u304b\u3068\u601d\u3046\u304c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7c21\u5358\u306a\u30c7\u30fc\u30bf\u5909\u63db\u3092\u884c\u3046\u30b9\u30af\u30ea\u30d7\u30c8\u3092Ruby\u3067\u66f8\u3044\u3066\u3044\u305f\u3002 \u306a\u3093\u3067Ruby\u304b\u3068\u3044\u3046\u3068\u3001\u4ed6\u306e\u76ee\u7684\u3067Ruby\u3092\u4f7f\u3063\u3066\u3044\u308b\u74b0\u5883\u3060\u3063\u305f\u304b\u3089\u3002 \u51e6\u7406\u3092\u66f8\u3044\u3066\u3044\u308b\u4e2d\u3067\u3001\u305d\u3046\u3044\u3048\u3070\u30a8\u30f3\u30c7\u30a3\u30a2\u30f3\u3092\u6307\u5b9a\u3057\u3066\u6574\u6570\u3068\u30d0\u30a4\u30c8\u5217\u3092\u5f80\u6765\u3059\u308b\u306b\u306f\u3069\u3046\u3059 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10472","post","type-post","status-publish","format-standard","hentry","category-computer"],"_links":{"self":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/10472","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10472"}],"version-history":[{"count":1,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/10472\/revisions"}],"predecessor-version":[{"id":10473,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=\/wp\/v2\/posts\/10472\/revisions\/10473"}],"wp:attachment":[{"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10472"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10472"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hdmr.org\/d\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}