Console output of unsigned chars (initialized by hex) gives cyrillic output

May 31, 2013 at 10:02am
Hi,

please, help to understand.

PROBLEM:I make the output with cout of unsigned chars, that are initialized as hex and receive ciryllic symbols on output with cout.
As I understand 0x63 is hex ASCII code of char 'c'; But I see cyrillic symbol 'я' instead... I don`t understand why!!!


CODE:

unsigned char Ar[2]={0x63,0x63};
cout << Ar[0]<<' '<< Ar[1]<< endl;


OUTPUT:
я я

SHOULD BE: c c




May 31, 2013 at 10:50am
Now insert your code snip in the simple program and test it

1
2
3
4
5
6
7
#include <iostream>

int main()
{
   unsigned char Ar[2]={0x63,0x63};
   std::cout << Ar[0]<<' '<< Ar[1]<< std::endl;
}


For example you can test the code online at www.ideone.com
Last edited on May 31, 2013 at 10:51am
May 31, 2013 at 12:06pm
It works....
I will try on my compiler and will post the result here...
Last edited on May 31, 2013 at 12:07pm
May 31, 2013 at 12:23pm
It looks like the problem is in somewhere else. The code snip you showed is irrelevant.
May 31, 2013 at 6:43pm
And what about this...(((


#include <iostream>
int main()
{
unsigned char Ar[2] ={0x7c,0xf2};
std::cout << Ar[0]<<' '<< Ar[1]<< std::endl;
}

OUTPUT: | �

What is a problem here...
May 31, 2013 at 8:05pm
Looks correct to me, 0x7c is the ascii code of |, and 0xf2 is invalid, which is correctly rendered as the replacement character �
May 31, 2013 at 8:31pm
0xf2 is ASCII code of '/'
May 31, 2013 at 8:54pm
I think you mean 0x2f is the ASCII code of '/'.
Last edited on May 31, 2013 at 9:20pm
Jun 1, 2013 at 10:05am
Thank You, Guys,

I thought, that hex will be outputted as chars latin symbols...from A-to z...
I looked through the ASCII table and understood my mistake.... that number of symbols in ASCII table are more than the number of only alphabetical chars)))

Thank You!

Topic archived. No new replies allowed.