Bintools 16 Binary Conversion

Source: Internet
Author: User

Package De.rtner.misc; Public classBintools { Public StaticFinal String hex ="0123456789ABCDEF";  PublicBintools () {super (); }     Public StaticString Bin2Hex (byte[] arg5)        {String v0; if(Arg5 = =NULL) {V0=""; }        Else{StringBuffer v1=NewStringBuffer (Arg5.length *2); intv0_1;  for(V0_1 =0; V0_1 < Arg5.length; ++v0_1) {                intV2 = (Arg5[v0_1] + the) % the; V1.append ("0123456789ABCDEF". CharAt (V2/ -& the)); V1.append ("0123456789ABCDEF". charAt (v2% -& the)); } v0=v1.tostring (); }        returnV0; }     Public Static intHex2bin (CharArg3) {        intV0; if(Arg3 < -|| Arg3 > $) {            if(Arg3 >= $&& Arg3 <= -) {                returnArg3- -; }            if(Arg3 >= the&& Arg3 <=102) {                returnArg3- the; }            Gotolabel_20; }        Else{v0= Arg3- -; }        returnV0; LABEL_20:Throw NewIllegalArgumentException (NewStringBuffer (). Append ("Input string contain hex digits, but found \ '"). Append (Arg3). Append ("\ '"). toString ()); }     Public Static byte[] Hex2bin (String arg5) {intV0 =0; if(Arg5 = =NULL) {Arg5=""; }        Else if(Arg5.length ()%2!=0) {Arg5=NewStringBuffer (). Append ("0"). Append (Arg5). toString (); }        byte[] v2 =New byte[Arg5.length ()/2]; intV1 =0;  while(V1 <arg5.length ()) {            intV3 = v1 +1; CharV4 =Arg5.charat (v1); V1= V3 +1; V2[v0]= ((byte) (Bintools.hex2bin (Arg5.charat (v3)) + bintools.hex2bin (v4) * -)); ++V0; }        returnv2; }     Public Static voidMain (string[] arg5) {intV4 = the; intV0 =0; byte[] V3 =New byte[V4]; bytev1;  for(V1 =0; V0 < V4; V1 = ((byte) (V1 +1)) {V3[v0]=v1; ++V0; } String v0_1=Bintools.bin2hex (v3); if(!v0_1.equals (Bintools.bin2hex (Bintools.hex2bin (v0_1))) {            Throw NewAssertionerror ("mismatch"); }    }}

Bintools 16 Binary Conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.