UTF8 encoding problem

S

SloppyCoder

I am having a problem preparing a UTF8 string for IPP (internet
printing protocol) transmission. Converting integers until 639 goes
well, but beyond this, in case of 640, results in an extra byte(?).
It shoot be 0x00, 0x00, 0x02 0x80 but I get : 00, 0x00, 0x02 0xc2
0x80.

Can somebody give me a hint, please?


private String Bytes4ToString(int fourbyte)
{

Byte[] temp=BitConverter.GetBytes(fourbyte);
char a=(char)temp[3];
char b=(char)temp[2];
char c=(char)temp[1];
char d=(char)temp[0];


StringBuilder result=new StringBuilder();
result.Append(a.ToString());
result.Append(b.ToString());
result.Append(c.ToString());
result.Append(d.ToString());

return result.ToString();

}

After this I send a stringbuilder instance "send" including this
"result" string to a webserver.

String send=build.ToString();

UTF8Encoding encoding=new UTF8Encoding();
Byte[]subdata= encoding.GetBytes(send);

TIA Gert
 
J

Jon Skeet [C# MVP]

SloppyCoder said:
I am having a problem preparing a UTF8 string for IPP (internet
printing protocol) transmission. Converting integers until 639 goes
well, but beyond this, in case of 640, results in an extra byte(?).
It shoot be 0x00, 0x00, 0x02 0x80 but I get : 00, 0x00, 0x02 0xc2
0x80.

Can somebody give me a hint, please?

You seem to be confusing character data and binary data. I very much
doubt that the printing protocol *really* expects its data to come as
UTF-8 encoded strings which themselves aren't really text but contain
unicode characters for binary values. I'd be very surprised if numbers
such as 129 are doing what you expect them to either.

You're converting into UTF-8 and back at the moment - do you have a
document describing what is actually expected at the other end? What
are *you* expecting?
 

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

Top