Tuesday, 11 September 2012

Binary, Hexadecimal, and Stuff

E.g. covert 255 to binary.
255 = 11111111

MING YIN in binary is 01001101 01101001 01101110 01100111 00100000 01011001 01101001 01101110


In the C language, a word is most often called an integer, abbreviated int. An integer can be used to represent numbers that range from negative to positive values, or numbers that have only positive values. In other words, an integer can be signed or unsigned. A signed integer can have either positive or negative values. An unsigned integer can only be positive. An unsigned 16-bit integer can have values from 0 through 65535. It is often abbreviated simply as unsigned.

SBit 15 is used as a sign bit for signed integers. If it is on, the number is negative. If it is off, it is positive. Positive values can range from 0 to 32767. Negative values can range from -1 to -32768. Some examples are shown below. Notice that the signed version is equal to -1 * (65536 - unsigned version). For example, to get the signed number from the unsigned value 49151, signed = -1 * (65536 - 49151) = -16385. 
HEX 8000 BFFF FFFE FFFF 0000 3FFF 7FFE 7FFF
Signed -32768 -16385 -0002 -0001 00000 16383 32766 32767
Unsigned 32768 49151 65534 65535 00000 16383 32766 32767

No comments:

Post a Comment