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

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

Deep
Guest
Posts: n/a

 02-27-2007
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.

mark_bluemel@pobox.com
Guest
Posts: n/a

 02-27-2007
On Feb 27, 11:43 am, "Deep" <(E-Mail Removed)> 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?

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

> 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?

Richard Bos
Guest
Posts: n/a

 02-27-2007
"Deep" <(E-Mail Removed)> 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?

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

Martin Ambuhl
Guest
Posts: n/a

 02-27-2007
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
Always try to do your own homework. None of us wants to depend on
someone who cheated his way through school.

Martin Ambuhl
Guest
Posts: n/a

 02-27-2007
Richard Bos wrote:
> "Deep" <(E-Mail Removed)> 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.

CBFalconer
Guest
Posts: n/a

 02-27-2007
Richard Bos wrote:
> "Deep" <(E-Mail Removed)> 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>

Nick Keighley
Guest
Posts: n/a

 02-28-2007
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?

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,
(XML in a Nutshell)