how to read/write a characters stream which is either of one byte/2 byte

Discussion in 'C Programming' started by Deep, Feb 27, 2007.

  1. Deep

    Deep Guest

    Suppose there is a character of one byte then max characters possible
    under this are 256.
    If characters are of two bytes then max chars should be 65536.
    Now if character can be of one byte or two byte then how many
    characters are possible and why?

    Also write a program to read and write characters in such type of
    encoding.

    Would you people help me to do this?


    regards,
    deep.
     
    Deep, Feb 27, 2007
    #1
    1. Advertising

  2. Deep

    Guest

    On Feb 27, 11:43 am, "Deep" <> wrote:
    > Suppose there is a character of one byte then max characters possible
    > under this are 256.
    > If characters are of two bytes then max chars should be 65536.
    > Now if character can be of one byte or two byte then how many
    > characters are possible and why?


    Homework alert!

    > Also write a program to read and write characters in such type of
    > encoding.


    Homework alert!

    > Would you people help me to do this?


    What have you tried so far?

    One hint - how would you distinguish between a one byte character and
    a two byte character? What would be the implications of that?
     
    , Feb 27, 2007
    #2
    1. Advertising

  3. Deep

    Richard Bos Guest

    "Deep" <> wrote:

    > Suppose there is a character of one byte then max characters possible
    > under this are 256.


    Wrong.

    > If characters are of two bytes then


    ....then you're not talking about C.

    > Now if character can be of one byte or two byte then how many
    > characters are possible and why?


    Impossible to answer without more information, even if I assume that
    you're deliberately being off-topic by asking about something else than
    C..

    > Also write a program to read and write characters in such type of
    > encoding.


    Do your own homework, may Cthulhu make slush of your spinal cord!

    Richard
     
    Richard Bos, Feb 27, 2007
    #3
  4. Re: how to read/write a characters stream which is either of onebyte/2 byte

    Deep wrote:
    > Suppose there is a character of one byte then max characters possible
    > under this are 256.


    Not true. A byte or char has CHAR_BIT bits, and can have
    pow(2,CHAR_BIT) states. That number need not, and in many cases is not 256.

    > If characters are of two bytes then max chars should be 65536.


    Not true. The world is not defined by the toy box in front of you.

    > Now if character can be of one byte or two byte then how many
    > characters are possible and why?


    Suppose you have a two-byte sequence representing a single character
    byte1:byte2
    How do you know that this is not a two character sequence? The easiest
    way is to have some bit which is never set or always set in a single
    byte character. Suppose that it is always set for the first byte of a
    two byte character and never set for a single byte character.
    Then you can have
    pow(2,CHAR_BIT-1) single byte characters and
    pow(2,2*CHAR_BIT-1) two byte characters.
    >
    > Also write a program to read and write characters in such type of
    > encoding.
    >
    > Would you people help me to do this?


    I've already given you more help than you deserve. Show us some code
    and describe your problem, and we may be able to help you fix it.
    Always try to do your own homework. None of us wants to depend on
    someone who cheated his way through school.
     
    Martin Ambuhl, Feb 27, 2007
    #4
  5. Re: how to read/write a characters stream which is either of onebyte/2 byte

    Richard Bos wrote:
    > "Deep" <> wrote:
    >
    >> Suppose there is a character of one byte then max characters possible
    >> under this are 256.

    >
    > Wrong.
    >
    >> If characters are of two bytes then

    >
    > ...then you're not talking about C.
    >


    Be fair. "chars" and "characters" are different things. If he had said
    "If chars are of two bytes" then your comment would make sense. But he
    didn't.
     
    Martin Ambuhl, Feb 27, 2007
    #5
  6. Deep

    CBFalconer Guest

    Re: how to read/write a characters stream which is either of one byte/2byte

    Richard Bos wrote:
    > "Deep" <> wrote:
    >
    >> Suppose there is a character of one byte then max characters
    >> possible under this are 256.

    >
    > Wrong.


    Because that depends on the value of CHAR_BIT. 16777216 is also a
    possibility.


    --
    Chuck F (cbfalconer at maineline dot net)
    Available for consulting/temporary embedded and systems.
    <http://cbfalconer.home.att.net>
     
    CBFalconer, Feb 27, 2007
    #6
  7. Deep wrote:

    > Suppose there is a character of one byte then max characters possible
    > under this are 256.


    be careful. In C bytes and chars are the same thing. So if a C char
    were
    16-bits then a byte is (by definition) also 16-bits.

    You should either say "8-bit characters" or "1 octet characters"

    > If characters are of two bytes then max chars should be 65536.


    "if characters accupy two octets then the maximum number of
    characters
    possible is 65536"


    > Now if character can be of one byte or two byte then how many
    > characters are possible and why?


    beats me. We'd need to know more about your encoding scheme.

    Perhaps single octet characters could be 00..7F (top bit never set)
    and
    double octet characters 1000..FFFF (top bit in first octet always
    set).
    So how many distict characters can this encoding scheme represent?


    > Also write a program to read and write characters in such type of
    > encoding.


    let's see what you have so far. What internal representation are you
    going to use? What are these characters for?


    > Would you people help me to do this?




    --
    Nick Keighley

    Unicode is an international standard character set that can be used
    to write documents in almost any language you're likely to speak,
    learn or encounter in your lifetime, barring alien abduction.
    (XML in a Nutshell)
     
    Nick Keighley, Feb 28, 2007
    #7
    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. crash.test.dummy
    Replies:
    1
    Views:
    939
    Knute Johnson
    Feb 17, 2006
  2. moralbarometer
    Replies:
    8
    Views:
    518
    moralbarometer
    Mar 5, 2007
  3. dolphin
    Replies:
    6
    Views:
    558
    Thomas Fritsch
    Mar 18, 2007
  4. JX
    Replies:
    1
    Views:
    310
  5. Roedy Green

    byte stream vs char stream buffer

    Roedy Green, May 7, 2014, in forum: Java
    Replies:
    20
    Views:
    205
    Silvio
    May 18, 2014
Loading...

Share This Page