Syntax error com.hurlant.util.hex on air sdk 3.5

I have an application written and compiled with an older version of flex sdk. Now I need to transfer this application to mobile devices, so I changed sdk to air sdk 3.5. I am using hurlant library for encryption / decryption. bu on the Hex class there is a line that throws an error.

if (hex.length&1==1) hex="0"+hex; 

I do not know what (hex.length & 1 == 1) means. So, how do I change the string or any other solutions for this problem?

+1
source share
3 answers

I also saw this error, this happens when compiling with the new ASC2.0 Flash Builder 4.7 compiler.

I changed if (hex.length&1==1) hex="0"+hex; in

  if ((hex.length&1)==1) hex="0"+hex; 

and it fixed him.

+4
source

You will need both flexible and airy! looks like a typo to me ..

if (hex.length==1) hex="0"+hex;

depending on what the if statement should look for

EDIT MY Bad
I did not know about this Operator, I would do it with a module!
I lean towards your superior skills.

0
source

if(hex.length&1==1) means that it checks if hex.length is an odd number (1,3,5,7 ...).

specify a as follows:

 var str:String = "111"; if(str.length&1==1) { str = "0" + str; trace(str); } 

your syntax is not a problem. I am sure that. what error is displayed?

I have Hex.as but no syntax error occurs. In Flash Builder 4.6, Flash CS6 AIR3.5.

 package com.hurlant.util { 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); } } } 
0
source

Source: https://habr.com/ru/post/1501335/


All Articles