Character -48= integer
Give you a program
Run it.
be clear/manifest at a glance
Master ()
{ char a;
a = 1;
Printf ("when a =1\ n");
Printf ("Integer: %d\n ",a);
Printf ("character type: %c\n", a);
a = ' 1 ';
Printf ("when a ='1'\ n");
Printf ("Integer: %d\n ",a);
Printf ("character type: %c\n", a);
a = ' 1 '-48;
printf(" a = ' 1 '-48 \ n ");
Printf ("Integer: %d\n ",a);
Printf ("character type: %c\n", a);
}
2. How does C language convert unsigned integers into floating-point types?
C language unsigned integer into floating point method is as follows:
Unsigned int x =123;
1, output cast, such as:
printf("%f ",x); This kind of output will lead to abnormal output data because %f and x are of different types.
printf("%f ",(float)x); Forced conversion to floating-point type can output correctly.
2, stored in the corresponding variables, such as:
Floating point fVal
fVal = x; The system will implicitly convert because the most significant digit of float is 7, so not all integers can be represented by float type variables, so it is better to use double type to store any integer.
printf("%f ",fVal); The output is normal
Double dVal
dVal = x; The system will convert implicitly.
printf("%f ",dVal); The output is normal
3. How to convert integers into characters in C++
There is integer/string conversion in my space.
Write functions separately:
1) converts an ASCII string into a signed integer;
2) Convert signed integers into ASCII strings.
int str toint(char str[]);
void IntToStr( int num,char str[]);
What are the characteristics of ASCII values of numeric characters? They are arranged in reverse order; The ASCII value of the character "0" plus 1 is equal to the ASCII value of "1", and so on. Therefore, the ASCII value of a numeric character is equal to the number plus the ASCII value of the character "0". (Note that the ASCII value of the character "0" is not equal to zero, which represents the character "0". That is to say, by subtracting the ASCII value of the character "0" from the ASCII value of the numeric character, the integer representation of the number can be obtained. Maybe I don't know what the ASCII value of the character "0" is, but the compiler knows that as long as the code "–0" is written, the compiler will interpret it as "subtracting the ASCII value of the string" 0 ". On the other hand, if you add the ASCII value of the character "0" to the number, you should get the corresponding digital character (that is, convert the number into a character).
int StrToInt( char str[])
{
int i = 0,isNeg = 0,num = 0;
if ( str[0] = ="-")
{
isNeg = 1;
I = 1;
}
while (str[i])
{
num * = 10;
num+=(str[i++]–' 0 ');
}
If (isNeg)
num * =- 1;
Quantity returned;
}
#define MAX_DIGITS_INT 10
void IntToStr( int num,char str[])
{
int i = 0,j = 0;
int isNeg = 0;
char temp[MAX _ DIGITS _ INT+2];
if(num & lt; 0 )
{
num * =- 1;
isNeg = 1;
}
do
{
temp[i++]=(num % 10)+' 0 ';
num/= 10;
} while(num);
If (isNeg)
temp[i++]= '- 1 ';
while(I & gt; 0)
str[j++]= temp[-I];
str[j]= ' \ 0 ';
}
4. How to convert the number of characters into integers?
Character type -48= integer. I'll give you a program to run and you'll understand main(){ char a;; a = 1; Printf ("when a =1"); Printf ("integer: %d", a); Printf ("character type: %c", a); a = ' 1 '; Printf ("when a ='1'"); Printf ("integer: %d", a); Printf ("character type: %c", a); a = ' 1 '-48; printf(" a = ' 1 '-48 "); Printf ("integer: %d", a); Printf ("character type: %c", a); }。
5. How to use C language to convert plastics into characters?
First, integers are replaced by characters.
If it is a single digit from 0 to 9, just +'0'.
If it is a multi-bit integer, the simplest method is to use the sprintf function, for example:
# include & ltstdio.h & gt
int main()
{
int num = 1 1298;
char str[5];
sprintf(str," %d ",num);
printf("%s ",str); Print out "1 1298"
Returns 0;
}