/* * Class written by Xavier MARTIN (xxlm or zeflasher) * http://dev.webbymx.net * http://www.webbymx.net * If you are using this class, I will be glad to receive a picture of you front of your city hall ( or wherever outside ) * To do so please visit http://dev.webbymx.net and go in the about page to get my details... * Licence: http://creativecommons.org/licenses/by-nc-sa/2.0/fr/deed.en */ class net.webbymx.files.Hexa { /* **************************************************************************** * CONSTRUCTOR **************************************************************************** */ private function Hexa() {} /* **************************************************************************** * PUBLIC STATIC FUNCTIONS **************************************************************************** */ private static function fillZeroBytes( s : String ) : String { var l : Number; if ( arguments[ 1 ] != undefined && typeof( arguments[ 1 ] ) == "number" ) l = arguments[ 1 ]; if ( l == undefined || ( l % 2 != 0 ) ) l = s.length + ( ( s.length % 2 ) ) for ( var i : Number = s.length; i < l; ++i ) s = s + "0"; return s; } /** * return the Hexa for a byte from * @param s : the hexa string passed to be encoded to be write in binary files * @return */ public static function getByte ( s : String ) : String { return getString( s, 2 ); } /** * return the Hexa for a Word ( 2 bytes ) from * @param s : the hexa string passed to be encoded to be write in binary files * @return the hexa string encoded */ public static function getWord ( s : String ) : String { return getString( s, 4 ); } /** * return the Hexa for a DWord ( 4 bytes ) from * @param s : the hexa string passed to be encoded to be write in binary files * @return the hexa string encoded */ public static function getDWord ( s : String ) : String { return getString( s, 8 ); } /** * Get the Hexa from * @param s : the hexa string passed to be encoded to be write in binary files * @param l : the length of the string to be returned * @return the hexa string encoded */ public static function getString( s : String, l : Number ) : String { var r : String = ""; // if string lenght > 0 then check for bytes and create the string to read from right to left while ( s.length > 0 ) { if ( s.length >= 2 ) { r += s.substring( s.length-2 ) s = s.slice( 0, s.length-2 ) } else { r += "0" + s; s = ""; } } // fille the rest of the string with zero r = fillZeroBytes(r, l ); return r } }