DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 6 of 6

Thread: Character data type

  1. #1
    Join Date
    Feb 2006
    Posts
    13

    Character data type

    Hello everyone,

    Actually I don't have question, but I get confused with character data type in C language. In one book I read that

    Data type range
    char -128 to 127
    unsigned char 0 to 255

    In C char is data type which has ASCII values associated with it and ASCII values are positive. It is true or not. Please help me.

    Thank you,
    rathorek

  2. #2
    Join Date
    May 2006
    Posts
    48
    Yes, ASCII values are always positive ranging from 0 to 255.

    You can see the characters associated with them here: http://www.lookuptables.com/

    Ascii values are the same as Dec

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    Not quite. First off, char isn't necessarily ASCII. On IBM machines it's EBCDIC and theoretically, it could be any byte-sized encoding.
    Secondly, ASCII values can be negative. This happens when you try to queeze 255 ASCII code into a signed char. Why do that? Supporting a multilingual system, say Hebrew and English, requires that some characters be mapped to negative values if char is signed by default. From my own experience, it works pretty well.
    Danny Kalev

  4. #4
    Join Date
    Dec 2003
    Posts
    3,366
    ASCII was 0-127 initially as well, the second "half" was added much later on.

  5. #5
    Join Date
    Nov 2003
    Posts
    4,118
    ASCII was indeed a 128 sign system originally. However, EBCDIC began as a 225 symbol system so it has always needed at least 8 bits. Histroically, EBCDIC was based on BCDIC which used 6 bits (IIRC) back in the days of mechanical computing machines of the 1920s and 1930s. But the point is: char isn't necessarily 8 bits long, char isn't necessarily an ASCII value, and (extended) ASCII values can be negative.
    Danny Kalev

  6. #6
    Join Date
    Feb 2006
    Posts
    13
    Thanks to all for your reply.

    rathorek

Similar Threads

  1. SQL servicer script, data type for MEMO
    By DH in forum VB Classic
    Replies: 2
    Last Post: 08-08-2007, 07:03 AM
  2. Replies: 0
    Last Post: 10-11-2002, 10:52 AM
  3. Altering created Distinct Data Type
    By Sindhu in forum Database
    Replies: 0
    Last Post: 12-06-2001, 12:28 PM
  4. Data type mismatch
    By Maria in forum VB Classic
    Replies: 0
    Last Post: 05-01-2001, 06:01 PM
  5. Replies: 1
    Last Post: 04-24-2001, 09:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center