{"id":482,"date":"2022-08-30T15:02:05","date_gmt":"2022-08-30T15:02:05","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/09\/problem-about-endianness-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:02:05","modified_gmt":"2022-08-30T15:02:05","slug":"problem-about-endianness-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/problem-about-endianness-collection-of-common-programming-errors\/","title":{"rendered":"problem about endianness-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/ZUL0U.png?s=32&amp;g=1\" \/><br \/>\nMOHAMED<br \/>\nc build endianness htonl<br \/>\nI m playing with open source which contains the following codeuint32_t addr = htonl(* (uint32_t *)RTA_DATA(rth)); if (htonl(13) == 13) {\/\/ running on big endian system } else {\/\/ running on little endian systemaddr = __builtin_bswap32(addr); }It looks like it check if the system is a big endian or little endian with if (htonl(13) == 13). is it correct? and could you please explain why the check this in t<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/1667c942861ca8dfa7a47df0c8786f90?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nalartur<br \/>\nc type-conversion endianness<br \/>\nI am looking for the fastest way to read numerical values stored in binary files.I have done some functions that seem to work, but I&#8217;d like to get a feedback on whether or not my implementation is good.Here is how I get a signed integer from a 4-bytes little endian block:signed long int from4li(char const * const buffer) {signed long int value = 0;value += (unsigned char) buffer[3];value<\/li>\n<\/ul>\n<p id=\"rop\"><small>Originally posted 2013-11-09 19:45:12. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>MOHAMED c build endianness htonl I m playing with open source which contains the following codeuint32_t addr = htonl(* (uint32_t *)RTA_DATA(rth)); if (htonl(13) == 13) {\/\/ running on big endian system } else {\/\/ running on little endian systemaddr = __builtin_bswap32(addr); }It looks like it check if the system is a big endian or little [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-482","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/482","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=482"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/482\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=482"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=482"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=482"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}