Utility class to convert Hex strings to ByteArray or String types.
import flash.utils.ByteArray; public class Hex { /** * Support straight hex, or colon-laced hex. * (that means 23:03:0e:f0, but *NOT* 23:3:e:f0) * Whitespace characters are ignored. */ public static function toArray(hex:String):ByteArray { hex = hex.replace(/\s|:/gm,''); var a:ByteArray = new ByteArray; if (hex.length&1==1) hex="0"+hex; for (var i:uint=0;i<hex.length;i+=2) { a[i/2] = parseInt(hex.substr(i,2),16); } return a; } public static function fromArray(array:ByteArray, colons:Boolean=false):String { var s:String = ""; for (var i:uint=0;i<array.length;i++) { s+=("0"+array[i].toString(16)).substr(-2,2); if (colons) { if (i<array.length-1) s+=":"; } } return s; } /** * * @param hex * @return a UTF-8 string decoded from hex * */ public static function toString(hex:String):String { var a:ByteArray = toArray(hex); return a.readUTFBytes(a.length); } /** * * @param str * @return a hex string encoded from the UTF-8 string str * */ public static function fromString(str:String, colons:Boolean=false):String { var a:ByteArray = new ByteArray; a.writeUTFBytes(str); return fromArray(a, colons); } }
內容均為作者獨立觀點,不代表八零IT人立場,如涉及侵權,請及時告知。
相關文章
- json convert to stringJSON
- Convert string to binary and binary to string in C#C#
- Discuz! x3.1 /utility/convert/index.php Code Execution VulIndexPHP
- How to Convert Class File to Java File Online?Java
- C# convert sql blob type to plain stringC#SQLAI
- PHP 每日一函式 — 字串函式 convert_cyr_string ()PHP函式字串
- err Invalid input of type: 'dict'. Convert to a byte, string or number first
- MyBatisSystemException There is no getter for property named 'id' in 'class java.lang.String'MyBatisExceptionJava
- There is no getter for property named 'userIds' in 'class java.lang.String'Java
- 【Hex】什麼是英特爾 HEX 檔案格式
- dbverify Utility
- DirectShow Utility
- COM Utility
- Utility FilterFilter
- Convert DataFrame string complex i to j python // “Cloning” row or column vectorsPython
- hex檔案分析
- PG: Utility queries
- dbms_utility
- DBNEWID Utility
- MQTT接收HEX(2/2)MQQT
- python函式每日一講 - bytearrayPython函式
- DBVERIFY utility的使用
- 開源飛行器 HEX
- css12 CSS HEX ColorsCSS
- A Facial Recognition utility in a dozen of LOC
- ASM Metadata Dump UtilityASM
- DBMS_Utility學習
- DBMS_UTILITY.ANALYZE_SCHEMA
- dbms_utility.get_time
- Analyzing Strings with sscanf
- 字串函式 hex2bin ()字串函式
- Partition|Disk Utility 如何分割磁碟
- SMART Utility for mac (硬碟檢測)Mac硬碟
- File Compare Utility 3.0.002
- DBMS_UTILITY.COMPILE_SCHEMACompile
- enable run glance utility in windows CMDWindows
- 04_python——元組(tuple)、字串 、 bytes bytearrayPython字串
- Python內建資料結構--bytes、bytearrayPython資料結構