how do i convert a unsigned char to int ?
-
unsigned char uc = 15;
int i = uc;[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
unsigned char g = 42;
int h = g;Mark Salsbery Microsoft MVP - Visual C++ :java:
-
unsigned char uc = 15;
int i = uc;[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
whoa - that's creepy :) Would be scary if we used the same variable names and value.
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
whoa - that's creepy :) Would be scary if we used the same variable names and value.
Mark Salsbery Microsoft MVP - Visual C++ :java:
wait, I have better code:
unsigned char uc = 15;
int i = (signed int)(unsigned int)(unsigned short)uc;[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
wait, I have better code:
unsigned char uc = 15;
int i = (signed int)(unsigned int)(unsigned short)uc;[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Extreme coercion....I like it!
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
Unsigned data can only hold positive data, whereas signed data can hold both positive and negative data. In your case, the unsigned data is a char, and the signed one is an int and the conversion goes on smoothly. Converting an unsigned double to a signed int MAY be disastrous, depending on the value of the double. You Google for signed vs unsigned - these are the basics. :)
Many are stubborn in pursuit of the path they have chosen, few in pursuit of the goal - Friedrich Nietzsche .·´¯`·->Rajesh<-·´¯`·. [Microsoft MVP - Visual C++]