Thread: how the char data type stores the character

  1. #1
    Registered User
    Join Date
    Jul 2022
    Posts
    17

    how the char data type stores the character

    I am trying to understand how char data type stores characters. The size of char data type is 1 byte, which means that the compiler can store a maximum of 255 characters.



    ASCII Table show 0 to 255 values
    ASCII Table - ASCII codes,hex,decimal,binary,html

    unsigned defined between 0 to 256
    signed defined between -127, 0, 128

    What I am trying to find here is what characters are stored in the range of 0 to -127. This table does not show the character list for range -127 to 0

  2. #2
    Registered User
    Join Date
    May 2012
    Location
    Arizona, USA
    Posts
    945
    The char data type is not defined as either signed as unsigned. It's implementation defined whether it's signed or unsigned by default.

    And ASCII defines only 128 characters (0 through 127). There are a number of 8-bit character sets (some people call them "extended ASCII" since they contain the same 128 characters plus 128 more characters, but they are not actually ASCII) that define characters above 127. For example, ISO8859 or the old-school MSDOS "code pages" or Windows-1252.

    But most commonly these days you'll find UTF-8 which is a variable-length encoding (from 1 to 4 bytes per character); the way UTF-8 is designed, all valid ASCII text is also valid UTF-8 text.

  3. #3
    Registered User
    Join Date
    Dec 2017
    Posts
    1,626
    Quote Originally Posted by king12 View Post
    ASCII Table show 0 to 255 values
    Standard ASCII is a 7-bit code so is only defined for 0 to 127. The high bit is used as a parity bit.
    Extended systems can define values for 128 to 255.

    Quote Originally Posted by king12 View Post
    unsigned defined between 0 to 256
    You mean 0 to 255.

    Quote Originally Posted by king12 View Post
    signed defined between -127, 0, 128
    You mean -128 to +127 for the common 2's complement representation (although the standard only requires -127 to +127).

    Quote Originally Posted by king12 View Post
    This table does not show the character list for range -127 to 0
    You mean -128 to -1, but the values -128 to -1 share the same bit pattern as the values 128 to 255. Look up 2's complement representation.
    A little inaccuracy saves tons of explanation. - H.H. Munro

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'char' integer type or character type?
    By password636 in forum C Programming
    Replies: 5
    Last Post: 09-26-2012, 09:50 AM
  2. differentiate the character data type
    By cplusplus.Jr in forum Windows Programming
    Replies: 5
    Last Post: 04-05-2007, 01:41 PM
  3. Data Member of type char
    By oranges in forum C++ Programming
    Replies: 11
    Last Post: 11-23-2006, 12:02 AM
  4. length of char data type.
    By PING in forum C Programming
    Replies: 18
    Last Post: 01-09-2005, 04:07 PM
  5. Replies: 5
    Last Post: 05-30-2003, 12:46 AM

Tags for this Thread