Home > Back-end >  The C language
The C language

Time:03-25

STR [I] - '0' why not 'a' operations,
'a' - '0'=49, why not

CodePudding user response:

'a' corresponding decimal ASCII is 65 0 x61, namely the '0' ~ '9' corresponding is 0 x30 ~ 0 x39

General to '0' - '9' character is poor compared to '0' and do
General is' A '-' Z 'and' A 'poor comparison and do

In the same way, 'a' - 'z' and 'a'

CodePudding user response:

Computer memory or file content or transport it is just a one-dimensional binary byte array and its corresponding binary address;
The human brain to a computer memory or file contents or transfer the content of the one-dimensional binary byte array and its corresponding binary address some parts as an integer, number of signed/unsigned number, floating point Numbers, complex Numbers, letters, digits, Chinese/Korean/French... Character/string, assembly instructions, functions, function parameters, heap, stack, arrays, Pointers, array pointer and pointer array, the array of arrays, pointer to pointer, two-dimensional arrays, character lattice, the coordinates of character strokes, black and white binary images and grayscale images, color images, audio, video, fingerprint information, id information...

Recommended WinHex software to check the hard disk or file or original bytes of memory content,

CodePudding user response:

Fyi:
 # include & lt; stdio.h> 
# include & lt; String. H>
The FILE * f;
Char buffer [4096].
Int r, a;
Void HexDump) (char * buf, int len, int addr) {
int i,j,k;
Char binstr [80].

for (i=0; IIf (0==16) (I %) {
Sprintf (binstr, "% x - 08", I + addr);
Sprintf (binstr, "% s % 02 x", binstr, buf (unsigned char) [I]);
} else if (15==16) (I %) {
Sprintf (binstr, "% s % 02 x", binstr, buf (unsigned char) [I]);
Sprintf (binstr, "% s", binstr);
For (j=I - 15; J<=i; J++) {
Sprintf (binstr, "% s % c," binstr, ('! '& lt; Buf [j] & amp; & Buf [j] <='~')? Buf [j] : '. ');
}
Printf (" % s \ n ", binstr);
} else {
Sprintf (binstr, "% s % 02 x", binstr, buf (unsigned char) [I]);
}
}
If (0! 16)=(I %) {
16 k=16 - (I %);
For (j=0; JSprintf (binstr, "% s", binstr);
}
Sprintf (binstr, "% s", binstr);
K=16 - k;
For (j=I - k; JSprintf (binstr, "% s % c," binstr, ('! '& lt; Buf [j] & amp; & Buf [j] <='~')? Buf [j] : '. ');
}
Printf (" % s \ n ", binstr);
}
}
Int main (int arg c, char * * argv) {
If (argc<2) {
Fprintf (stderr, "the Usage: % s filename. Ext \ n", argv [0]).
Return 2;
}
F=fopen (argv [1], "rb");
If (NULL==f) {
Fprintf (stderr, "Can not open the file [% s]! \ n ", argv [1]);
return 1;
}
A=0;
While (1) {
R=fread (buffer, 1409 (6), f);
The HexDump) (buffer, r, a);
A +=r;
If (r<4096) break;
}
The fclose (f);
return 0;
}

CodePudding user response:

 char a []="a". Cout & lt; 

CodePudding user response:

The
refer to the original poster m0_45257832 response:
STR [I] - '0' why not 'a' operation,
'a' - '0'=49, why do not calculate


There is no mechanism to prevent the operation, this is can

CodePudding user response:

As long as can be calculated in the sequence, not found the problem.

CodePudding user response:

So to calculate, but meaningless
STR [I] - '0' mean STR [I] is a '0' to '9' characters, STR [I] - '0' so we can calculate the values, such as' 2 '-' 0 'is equal to 2
STR [I] - 'a', STR [I] should be a letter corresponding characters, such as STR [I] - 'a' + 'a' can put a lowercase letters to uppercase letter
Used the above features, are actually in the ASCII, 0-9 a-z a-z is encoded in a row, but 0 with a code do not have what relation, so the different nature of the two characters subtraction is meaningless
  • Related