{"id":54,"date":"2015-10-12T06:27:24","date_gmt":"2015-10-12T04:27:24","guid":{"rendered":"http:\/\/lab.fawno.com\/?p=54"},"modified":"2022-03-07T01:03:10","modified_gmt":"2022-03-07T00:03:10","slug":"","status":"publish","type":"post","link":"https:\/\/lab.fawno.com\/en\/2015\/10\/12\/convertir-de-hexadecimal-a-binario-y-viceversa\/","title":{"rendered":"","raw":""},"content":{"rendered":"","protected":false,"raw":""},"excerpt":{"rendered":"","protected":false,"raw":""},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_coblocks_attr":"","_coblocks_dimensions":"","_coblocks_responsive_height":"","_coblocks_accordion_ie_support":"","_editorskit_title_hidden":false,"_editorskit_reading_time":0,"_editorskit_typography_data":[],"_editorskit_blocks_typography":"","_editorskit_is_block_options_detached":false,"_editorskit_block_options_position":"{}","_es_post_content":"\n
Para convertir una cadena Hexadecimal a Binario y viceversa PHP dispone de dos funciones:<\/p>\n\n\n\n
Sin embargo, tal y como advierte la documentaci\u00f3n, hex2bin s\u00f3lo est\u00e1 disponible a partir de la versi\u00f3n 5.4.0 de PHP.<\/p>\n\n\n\n
Como sea que no todos los entornos pueden ser actualizados es interesante crear dichas funciones con c\u00f3digo discreto:<\/p>\n\n\n\n
if (!function_exists('hex2bin')) {\n function hex2bin ($hex) {\n return pack('H*', $hex);\n }\n}\n\nif (!function_exists('bin2hex')) {\n function bin2hex ($bin) {\n return current(unpack('H*', $bin));\n }\n}<\/pre>\n\n\n\nEn este caso creamos ambas funciones, en caso de no existir, mediante las funciones pack<\/a> y unpack<\/a> que est\u00e1n presentes a partir de la versi\u00f3n 4 de PHP, lo que nos garantiza en gran medida poder utilizarlas en casi cualquier instalaci\u00f3n puesto que ser\u00eda harto dif\u00edcil encontrarnos una instalaci\u00f3n con PHP 3, en cuyo caso la actualizaci\u00f3n es de obligado cumplimiento.<\/p>\n","_es_post_name":"convertir-de-hexadecimal-a-binario-y-viceversa","_es_post_excerpt":"","_es_post_title":"Convertir de Hexadecimal a Binario y viceversa","_en_post_content":"","_en_post_name":"","_en_post_excerpt":"","_en_post_title":"","edit_language":"en","footnotes":""},"categories":[5,3],"tags":[6],"class_list":["post-54","post","type-post","status-publish","format-standard","hentry","category-php","category-tips","tag-php"],"ninja_gutenberg_blocks_featured_media_urls":{"thumbnail":"","ninja_gutenberg_blocks_landscape_large":"","ninja_gutenberg_blocks_portrait_large":"","ninja_gutenberg_blocks_square_large":"","ninja_gutenberg_blocks_landscape":"","ninja_gutenberg_blocks_portrait":"","ninja_gutenberg_blocks_square":"","full":""},"_links":{"self":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/54","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/comments?post=54"}],"version-history":[{"count":8,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/54\/revisions"}],"predecessor-version":[{"id":1847,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/posts\/54\/revisions\/1847"}],"wp:attachment":[{"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/media?parent=54"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/categories?post=54"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lab.fawno.com\/en\/wp-json\/wp\/v2\/tags?post=54"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}