{"id":392,"date":"2015-08-24T12:34:04","date_gmt":"2015-08-24T17:34:04","guid":{"rendered":"http:\/\/thenoyes.com\/littlenoise\/?p=392"},"modified":"2015-08-24T12:34:04","modified_gmt":"2015-08-24T17:34:04","slug":"swap-endian","status":"publish","type":"post","link":"https:\/\/thenoyes.com\/littlenoise\/?p=392","title":{"rendered":"Swap Endian"},"content":{"rendered":"<pre>\r\nCREATE FUNCTION SWAP_ENDIAN(inString text)\r\nRETURNS TEXT\r\nDETERMINISTIC\r\n-- Expects a hex string: AbCdEf\r\n-- Returns the string swapped for endianness: EfCdAb\r\n\r\nBEGIN\r\n  DECLARE position INT DEFAULT 1;\r\n  DECLARE holder TEXT DEFAULT '';\r\n\r\n  WHILE position < LENGTH(inString) DO\r\n    SET holder = CONCAT(SUBSTRING(inString, position, 2), holder);\r\n    SET position = position + 2;\r\n  END WHILE;\r\n\r\n  RETURN holder;\r\nEND<\/pre>\n<p>So you can do things like:<\/p>\n<pre>\r\nSELECT\r\n  FROM_UNIXTIME(\r\n    CONV(\r\n      SWAP_ENDIAN(\r\n        SUBSTRING(\r\n          HEX(\r\n            FROM_BASE64(\r\n              'Yk3XVQ8pAAAAZgAAAGoAAAAAAAQANS4xLjczLWxvZwAAAAAABBAAAAAAAAAAAAAAAA'\r\n              'AAAAAAAAAAAAAAAAAAAAAAAABiTddVEzgNAAgAEgAEBAQEEgAAUwAEGggAAAAICAgC'\r\n            )\r\n          ), 1, 8\r\n        )\r\n      ), 16, 10)\r\n  ) AS event_timestamp;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>CREATE FUNCTION SWAP_ENDIAN(inString text) RETURNS TEXT DETERMINISTIC &#8212; Expects a hex string: AbCdEf &#8212; Returns the string swapped for endianness: EfCdAb BEGIN DECLARE position INT DEFAULT 1; DECLARE holder TEXT DEFAULT &#8221;; WHILE position < LENGTH(inString) DO SET holder = CONCAT(SUBSTRING(inString, position, 2), holder); SET position = position + 2; END WHILE; RETURN holder; END [&hellip;]\n<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[4],"tags":[],"class_list":["post-392","post","type-post","status-publish","format-standard","hentry","category-mysql"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p2IBF1-6k","jetpack_sharing_enabled":true,"jetpack-related-posts":[],"_links":{"self":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/392","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=392"}],"version-history":[{"count":4,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/392\/revisions"}],"predecessor-version":[{"id":397,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=\/wp\/v2\/posts\/392\/revisions\/397"}],"wp:attachment":[{"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenoyes.com\/littlenoise\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}