May 31, 2013 at 10:02am May 31, 2013 at 10:02am UTC
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 May 31, 2013 at 10:50am UTC
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 10:51am UTC
May 31, 2013 at 12:06pm May 31, 2013 at 12:06pm UTC
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:07pm UTC
May 31, 2013 at 12:23pm May 31, 2013 at 12:23pm UTC
It looks like the problem is in somewhere else. The code snip you showed is irrelevant.
May 31, 2013 at 6:43pm May 31, 2013 at 6:43pm UTC
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 May 31, 2013 at 8:05pm UTC
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 May 31, 2013 at 8:31pm UTC
0xf2 is ASCII code of '/'
May 31, 2013 at 8:54pm May 31, 2013 at 8:54pm UTC
I think you mean 0x2f is the ASCII code of '/'.
Last edited on May 31, 2013 at 9:20pm May 31, 2013 at 9:20pm UTC
Jun 1, 2013 at 10:05am Jun 1, 2013 at 10:05am UTC
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!