Convert Chinese characters to binary, decimal, and hexadecimal display

Source: Internet
Author: User

Today, my netizen hunting locks talked to me about converting Chinese characters to hexadecimal notation. The conversion between binary, decimal, and hexadecimal is a headache for me. Now I add Chinese characters, which is undoubtedly "worse ". My brain is overwhelmed and my thoughts are messy. In the afternoon, I went to the library to check the materials and found no clues about the value. In the end, I did not discuss the answer.

With the help of my netizen "calm and calm", I finally found the relevant information on www.pudn.com and downloaded it to try it. It really realized the functions we wanted: convert the entered Chinese characters into binary, decimal, and hexadecimal. The program running effect is as follows:

 

The main code of the program is as follows:

Void cunicodedlg: ontranslate ()

{

// Todo: add your control notification handler code here

Updatedata (true );

Cstring pp;

Pp = m_chinesecharacters;

If (m_chinesecharacters.isempty ())

{

Afxmessagebox ("enter Chinese characters! ");

Return;

}

Int Len = pp. getlength ();

Int Unicode; // The median value used in hexadecimal notation.

Const int max_file_length = 500;

Wchar unicodefile [max_file_length];

Multibytetowidechar (cp_acp, 0, PP,-1, unicodefile, max_file_length );

Pp = "";

Cstring MIDD, temp = ""; // median value

For (INT loop = 0; loop <Len/2; loop ++)

{

Unicode = unicodefile [loop];

M_binary = tentobinary (UNICODE );

MIDD. Format ("% d", Unicode );

Temp. Format ("% d", Unicode );

M_unicodedec = m_unicodedec + temp;

M_unicodedec = m_unicodedec + "";

MIDD. Format ("% d", (UNICODE)/(16*16*16 ));

MIDD = tentosixteen (MIDD );

Pp = pp + MIDD;

Unicode = Unicode-(UNICODE)/(16*16*16) * 16*16*16;

MIDD. Format ("% d", (UNICODE)/(16*16 ));

MIDD = tentosixteen (MIDD );

Pp = pp + MIDD;

Unicode = Unicode-(UNICODE)/(16*16) * 16*16;

MIDD. Format ("% d", (UNICODE)/16 );

MIDD = tentosixteen (MIDD );

Pp = pp + MIDD;

Unicode = Unicode-Unicode/16*16;

MIDD. Format ("% d", Unicode );

MIDD = tentosixteen (MIDD );

Pp = pp + MIDD; // This is the final result

M_unicodehex = pp;

Updatedata (false );

}

}

 

Cstring cunicodedlg: tentosixteen (cstring ten)

{

If (ten = "10 ")

Ten = "";

If (ten = "11 ")

Ten = "B ";

If (ten = "12 ")

Ten = "C ";

If (ten = "13 ")

Ten = "D ";

If (ten = "14 ")

Ten = "E ";

If (ten = "15 ")

Ten = "F ";

Return ten;

}

Cstring cunicodedlg: tentobinary (INT inum)

{

Int I;/* loop variable */

Char A [17];/* Number of input outputs */

Memset (A, 0, 17 );

A [16] = '/0 ';

Printf ("Please input the number (> 0 ):");

Scanf ("% d", & inum );

For (I = 15; I> = 0; I --)

{

If (inum = 0)

{

For (; I> = 0; I --)

{

A [I] = '0 ';

}

Break;

}

If (inum % 2 = 0)

{/* If the hexadecimal number is divisible */

Inum = inum/2;

A [I] = '0';/* base number position */

}

Else

{

Inum = (iNum-1)/2;

A [I] = '1';/* otherwise set */

}

}

Return (cstring);

}

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/zhixingzhe/archive/2009/09/28/4610063.aspx

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.