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

D

Deep

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.
 
M

mark_bluemel

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

Richard Bos

Deep said:
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
 
M

Martin Ambuhl

Deep said:
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.
 
M

Martin Ambuhl

Richard said:
...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.
 
N

Nick Keighley

Deep said:
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)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top