Hexadecimal string and hexadecimal byte array Conversion

Source: Internet
Author: User
///   <Summary>
/// Convert a decimal string to hexadecimal
///   </Summary>
///   <Param name = "strcharset"> </param>
///   <Returns> </returns>
Public String Tensstringtohexstring ( String Strcharset)
{
Stringbuilder strbcharset = New Stringbuilder ();

Char[] Chararray = strcharset. tochararray ();

For(IntI =0; I <chararray. length; I ++)
{
Strbcharset. append (convert. tostring (chararray [I],16). Padleft (3,' '));
}

Return Strbcharset. tostring ();
}
///   <Summary>
/// Convert a decimal string to a decimal byte array
///   </Summary>
///   <Param name = "strcharset"> </param>
///   <Returns> </returns>
Public Byte [] Tensstringtobytearray ( String Strcharset)
{
Byte [] Buffer = New Byte [Strcharset. Length];

for ( int I = 0 ; I {< br> buffer [I] = convert. tobyte (strcharset. substring (I, 1 ), 10 );
}

ReturnBuffer;
}
//Hexadecimal conversion of hexadecimal byte Arrays
Public Byte[] Hexstringtobytearray (StringStrcharset)
{
Strcharset = strcharset. Replace (" ","");

Byte[] Buffer =New Byte[Strcharset. Length/2];

for ( int I = 0 ; I 2 )
{< br> buffer [I/ 2 ] = ( byte ) convert. tobyte (strcharset. substring (I, 2 ), 16 );
}

return buffer;
}< br> /// convert byte arrays to hexadecimal notation
Public string bytearraytohexstring ( byte [] btdata)
{< br> stringbuilder sbdata = New stringbuilder (btdata. length * 3 );

Foreach(ByteBInBtdata)
{
Sbdata. append (convert. tostring (B,16). Padleft (2,'0'). Padright (3,' '));
}

ReturnSbdata. tostring (). toupper ();
}

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.