ASCII in C ++ and Java

Source: Internet
Author: User

Rape is easy to hide, and obscenity is hard to prevent. Today, I am severely molated by ASCII code, but I may not be able to hide the mathematical relationship in the future, however, I believe that with this website, I have a good reference for the speed of code query. I always feel that I have been plagued by some strange problems recently and have encountered them in my actual work and study. Sometimes it is just a small problem. The root cause is that my previous deep-rooted ideas have not changed.
Next, I will use some ASCII comparisons in C ++ and Java to solve the problems that need to be paid attention when converting int to Char. By the way, I will list and analyze various web coding specifications I know, I hope to help you.
C ++ code
# Include <iostream>
Using namespace STD;
Int main (){

For (INT I = 0; I <300; I ++ ){
Char c = I;
Cout <I <"-" <C <"";
If (I % 10 = 0 ){
If (I! = 0 ){
Cout <Endl;
}
}
}
Cout <Endl;

Int EIG = 8;
Int eigs = '0' + 8;
Cout <"convert normal int to Char:" <(char) EIG <Endl;
Cout <"convert non-common int to Char:" <(char) eigs <Endl;

Char eigc = '8 ';
Char zeroc = '0 ';
Cout <"convert normal Char to int:" <(INT) eigc <Endl;
Cout <"convert normal Char to int:" <(INT) zeroc <Endl;
System ("pause ");
Return 0;
}

Java code:
Package com. j2-canvas;
Import java. util. Random;
Public class inttochar {
Public static void main (string [] ARGs ){
Random ran = new random ();

For (INT I = 0; I <200; I ++ ){
Char c = (char) I;
System. Out. Print (I + "-" + C + "");
If (I % 10 = 0 ){
If (I! = 0 ){
System. Out. println ();
}
}
}
System. Out. println ();

Int number = ran. nextint (10); // convert a common int to a char ::
Char x = (char) number;
System. Out. println (x); // garbled

Int number2 = '0' + ran. nextint (10); // convert non-common int to Char ::
Char X2 = (char) number2;
System. Out. println (X2); // No garbled characters

Char EIG = '0 ';
System. Out. println (INT) EIG );

}
}

The reason is that the ASCII code specification is 7 bits and the int value is 32 bits. In int + char, the int value has a higher priority, that is, the char automatically converts the ASCII value to the int value, so there are examples and scenarios like '0' + 8.
Next, let's take a look at common codes and their features:
An unfinished version will be added tomorrow !!!!!

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.