Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help newbie convert Hex to Char 1

Status
Not open for further replies.

serpento

Programmer
Joined
Jun 16, 2002
Messages
92
Location
GB
What is a better way to set a char to a hex value?
I can do it like:
[tt]
char c = 0xB0;
[/tt]
but I get a compiler warning:
[tt]
warning C4305: 'initializing' : truncation from 'const int' to 'char'
[/tt]
-Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
use type cast:
char c = (char)0xB0;
 
Thankyou, exactly what I wanted. -Ed ;-)

________________________________
Destiny is not a matter of chance; it is a matter of choice.
 
May I remember standard C++ hexadecimal-escape-sequence:
char ch = '\xB0'; // You don't need any type casts...
 
void main() {
int c = 0xB0;
cout << c << endl;
return;
}

// this will also work without requiring a cast. it's similar to your original thought.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top