I would like to transform a char into the corresponding int value, that represents the code value of the char. How?
Like this. char c = ‘A’; int i = c; Going the other way is just c = (char) i; This question crops up so frequently because the BASIC language uses functions to map characters into ints, ASC( ‘A’ ) => 65 causing BASIC programmers to seek the corresponding functions. The same is true for Pascal, Ada, and other languages. • (Sect. 6) Why does b >>>= 1 give me the same result as b >>= 1? “>>” is a “signed” or “arithmetic” shift, namely, it replicates the sign bit on the left as it shifts. The “>>>” operator is an “unsigned” or “logical” shift; it does a shift right and zero fill. However, “>>>” looks like it does a signed shift with negative bytes and shorts, where int promotion alters the sign. This occurs when you have a non-canonical type, byte, or short, with a negative value, e.g. byte b = -15; // 0xf1 b = (byte) b >>> 4; // why isn’t b 0x0f ? The initial expectation is that an unsigned shift right of 0xf1 would successively be (in binary) 0111_1000 then 0011_1100 then 0001_1110 then
Related Questions
- Im reading lines from a file into an array, with this code: char linebuf[80]; char *lines[100]; int i; for(i = 0; i < 100; i++) { char *p = fgets(linebuf, 80, fp); if(p == NULL) break; lines[i] = p; } Why do all the lines end up containing copies of the last line?
- I would like to transform a char into the corresponding int value, that represents the code value of the char. How?
- represents the code value of the char. How?