Re: Questions on conversions between char* to unsigned char* and vice versa

Discussion in 'C Programming' started by Navaneeth, Dec 31, 2010.

  1. Navaneeth

    Navaneeth Guest

    > That also assumes your target machine is using twos compliment system.

    My major platforms are LINUX, MAC and Windows.

    >
    > If you are using extended characters then possibly you may have
    > problems.


    Thanks. Can you tell me what do you meant by extended characters? My strings will be UTF8 encoded. Is that what you meant?
    Navaneeth, Dec 31, 2010
    #1
    1. Advertising

  2. Navaneeth

    Angus Guest

    On Dec 31, 12:52 pm, Navaneeth <> wrote:
    > > That also assumes your target machine is using twos compliment system.

    >
    > My major platforms are LINUX, MAC and Windows.
    >
    >
    >
    > > If you are using extended characters then possibly you may have
    > > problems.

    >
    > Thanks. Can you tell me what do you meant by extended characters? My strings will be UTF8 encoded. Is that what you meant?


    I am no computer science expert but if these 3 OS's are running on an
    Intel based platform then probably using twos compliment.

    If you have a look at an ASCII code chart the standard ASCII
    characters are from bit 1-7. Bit 8 is used for what I am referring to
    as extended characters. eg maybe on some locales eg Danish a specific
    Danish character may use all the 8 bits in the char 8 bit variable.

    UTF-8 uses the same bits as ASCII to represent ASCII characters so
    that would be fine. So only if you are using extended ASCII
    characters or some of the special UTF-8 eg FE small letter thorn could
    you have a problem.

    Thinking about it, even then I don't see how you would get a
    problem.

    Just to clarify something you may be confused about. Both signed and
    unsigned char is 8 bit. You don't lose any data converting between
    unsigned and signed char. If you had eg binary pattern 10000001
    unsigned char and converted to signed char, using twos compliment
    encoding, the result would be a negative integer. But what the byte
    of data represents is up to you.

    I hope this makes some sense.
    Angus, Dec 31, 2010
    #2
    1. Advertising

  3. Angus <> writes:
    [...]
    > Just to clarify something you may be confused about. Both signed and
    > unsigned char is 8 bit.


    Both signed and unsigned char are CHAR_BIT bits. CHAR_BIT is at least
    8, but it may be larger. (It's almost certain to be exactly 8 on any
    hosted implementation.)

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Dec 31, 2010
    #3
  4. Navaneeth

    Seebs Guest

    Re: Questions on conversions between char* to unsigned char* andvice versa

    On 2010-12-31, Navaneeth <> wrote:
    >> That also assumes your target machine is using twos compliment system.


    > My major platforms are LINUX, MAC and Windows.


    This is non-responsive, except in that Mac (not MAC, that's the 48-bit
    hardware addresses used by network interfaces) and Windows machines are
    all, so far as I know, on twos complement hardware. I am not at all sure
    that everything Linux runs on is twos complement. I wouldn't bet on it,
    certainly.

    -s
    --
    Copyright 2010, all wrongs reversed. Peter Seebach /
    http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
    http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
    I am not speaking for my employer, although they do rent some of my opinions.
    Seebs, Jan 1, 2011
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tim  Wong
    Replies:
    5
    Views:
    21,944
    Tim Wong
    Jan 21, 2005
  2. Replies:
    3
    Views:
    8,751
  3. Navaneeth
    Replies:
    8
    Views:
    677
    Keith Thompson
    Jan 1, 2011
  4. Navaneeth
    Replies:
    1
    Views:
    312
    Ben Bacarisse
    Jan 4, 2011
  5. Navaneeth
    Replies:
    3
    Views:
    325
    Thad Smith
    Jan 5, 2011
Loading...

Share This Page