{"id":3456,"date":"2024-10-08T09:33:00","date_gmt":"2024-10-08T00:33:00","guid":{"rendered":"http:\/\/43.203.250.216\/?p=3456"},"modified":"2024-10-05T23:35:17","modified_gmt":"2024-10-05T14:35:17","slug":"union%ec%9d%84-%ec%9d%b4%ec%9a%a9%ed%95%9c-byte-%eb%8b%a8%ec%9c%84-%ec%a0%91%ea%b7%bc","status":"publish","type":"post","link":"https:\/\/litcoder.com\/?p=3456","title":{"rendered":"Union\uc744 \uc774\uc6a9\ud55c byte \ub2e8\uc704 \uc811\uadfc"},"content":{"rendered":"\n<p>Big-endian\uc73c\ub85c \uc8fc\uc5b4\uc9c4 byte\ub4e4\uc744 little-endian\uc73c\ub85c \ubcc0\ud658\ud574\uc57c \ud558\ub294 \ubb38\uc81c\uac00 \uc0dd\uacbc\ub2e4. Byte\ub4e4\uc758 order\ub97c \uac70\uafb8\ub85c \ub9cc\ub4dc\ub294 \uac83\uc740 \uc5b4\ub835\uc9c0 \uc54a\uc9c0\ub9cc \uadf8\ub7ec\uae30 \uc704\ud574\uc11c\ub294 byte pointer\uac00 \uac00\ub9ac\ud0a4\ub294 element\ub4e4\uc744 1 byte \ub2e8\uc704\ub85c \uc811\uadfc\ud574\uc57c \ud55c\ub2e4. 1 byte\uc529 \ub4a4\uc9d1\uc740 \ub2e4\uc74c\uc5d0\ub294 \ubcc0\ud658\ub41c array\ub97c \uc6d0\ud558\ub294 \ud06c\uae30\uc758 \ud0c0\uc785\uc73c\ub85c \uc77d\ub3c4\ub85d type casting\uc744 \ud574\uc8fc\uc5b4\uc57c \ud55c\ub2e4.<\/p>\n\n\n\n<p>Union\uc744 \uc774\uc6a9\ud558\uba74 \ucf54\ub4dc\ub97c \ubabb\uc0dd\uae30\uac8c \ub9cc\ub4dc\ub294 pointer \uc9c1\uc811 \uc5f0\uc0b0\uc774\ub098 type casting\uc744 \ud558\uc9c0 \uc54a\uace0 \uc774\ub97c \uad6c\ud604\ud560 \uc218 \uc788\ub2e4. \uc989 union\uc740 \uc120\uc5b8\ub41c element\uc758 \uac00\uc7a5 \ud070 \ud06c\uae30 \ub9cc\ud07c\uc758 \uba54\ubaa8\ub9ac\uac00 \ud560\ub2f9 \ub418\ubbc0\ub85c \uac19\uc740 \ud06c\uae30\uc758 \ub450 element\ub97c \uc11c\ub85c \ub2e4\ub978 data type\uc73c\ub85c \uc120\uc5b8\ud558\ub294 \uac83\uc774\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">union\n{\n  int32_t v;\n  uint8_t b[4];\n} value;<\/pre>\n\n\n\n<p>\uc704\uc640 \uac19\uc774 \uc120\uc5b8\ud558\uba74 value.v = 0xdeadbeef \uac19\uc740 \uc2dd\uc73c\ub85c int32\ub97c \uc4f0\uac70\ub098 \uc77d\uc744 \uc218 \uc788\uace0 value.b[0] \uac19\uc774 \uac01 \uba54\ubaa8\ub9ac index\uc5d0 \uc811\uadfc \ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<p>Template\uc73c\ub85c \ub9cc\ub4e4\uc5b4\uc11c \uc5ec\ub7ec \ud0c0\uc785\uc5d0 \ub300\uc751 \ud560 \uc218 \uc788\ub2e4.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"cpp\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">    template &lt;typename T> T readFromBigEndian(uint8_t *b)\n    {\n      union\n      {\n        T v;\n        uint8_t b[sizeof(T)];\n      } dest;\n\n      union\n      {\n        T v;\n        uint8_t *b;\n      } src;\n\n      src.b = b;\n      for (int i = 0; i &lt; sizeof(T); ++i)\n      {\n        dest.b[i] = src.b[sizeof(T) - i - 1];\n      }\n      return dest.v;\n    }<\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Big-endian\uc73c\ub85c \uc8fc\uc5b4\uc9c4 byte\ub4e4\uc744 little-endian\uc73c\ub85c \ubcc0\ud658\ud574\uc57c \ud558\ub294 \ubb38\uc81c\uac00 \uc0dd\uacbc\ub2e4. Byte\ub4e4\uc758 order\ub97c \uac70\uafb8\ub85c \ub9cc\ub4dc\ub294 \uac83\uc740 \uc5b4\ub835\uc9c0 \uc54a\uc9c0\ub9cc \uadf8\ub7ec\uae30 \uc704\ud574\uc11c\ub294 byte pointer\uac00 \uac00\ub9ac\ud0a4\ub294 element\ub4e4\uc744 1 byte \ub2e8\uc704\ub85c \uc811\uadfc\ud574\uc57c \ud55c\ub2e4. 1 byte\uc529 \ub4a4\uc9d1\uc740 \ub2e4\uc74c\uc5d0\ub294 \ubcc0\ud658\ub41c array\ub97c \uc6d0\ud558\ub294 \ud06c\uae30\uc758 \ud0c0\uc785\uc73c\ub85c \uc77d\ub3c4\ub85d type casting\uc744 \ud574\uc8fc\uc5b4\uc57c \ud55c\ub2e4. Union\uc744 \uc774\uc6a9\ud558\uba74 \ucf54\ub4dc\ub97c \ubabb\uc0dd\uae30\uac8c \ub9cc\ub4dc\ub294 pointer \uc9c1\uc811 \uc5f0\uc0b0\uc774\ub098 type casting\uc744 \ud558\uc9c0 \uc54a\uace0 \uc774\ub97c \uad6c\ud604\ud560 \uc218 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5],"tags":[336,247,334,310,335],"class_list":["post-3456","post","type-post","status-publish","format-standard","hentry","category-programming","tag-array","tag-c","tag-endian","tag-template","tag-union"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/3456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3456"}],"version-history":[{"count":4,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/3456\/revisions"}],"predecessor-version":[{"id":3522,"href":"https:\/\/litcoder.com\/index.php?rest_route=\/wp\/v2\/posts\/3456\/revisions\/3522"}],"wp:attachment":[{"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/litcoder.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}