Sorry, I have gone through my code and find the place where my problem actually lies.
I hope to cast number in c++ approach. The original variable is unsigned char which I stored in a char variable a. Now I need to cast this a to double while keeping its original unsigned value. How could I do this ?
Edit:
I didn't expect my problem should be so confusing. Here is a brief example
unsigned char a;
double b;
a = 140;
char c = static_cast<char>(a);
b = static_cast<double>(c);
std::cout << b << std::endl;
This prints a result of -116, but what I actually hopes is a double 140. How could I do this then ?
Edit v2:
The scene is like this: I read 1024 bytes from a file with fstream. The 1024 bytes contains int numbers as well as unsigned char numbers. These unsigned char numbers I mean to cast to double types. I simplly read all of them to a std::vector<char> array, and then I need to unpack these numbers. Some part of them are to be cast to double and I met my problem here.
If my problem is brought by abuse of c++, what is the correct way to handle this task please ?
char unsigned ch = 129; double d = static_cast<double>(ch);dIS129.you are doing something different.doubleshould not result in-127. Can you edit your question to include the portion of your code where you believe your issue is coming from?