So I am converting a bunch of very large #s to what I believe is the ASCII standard? or something similar. And I am getting some negative values which is bad, needless to say. the values are the exact value of the conjugate.

Example

Should be value 214, instead I get -42. Taking the absolute Value of 42, 42 + 214 = 256. Every one of these pairs with the absolute value is 256. I need the value 214. So i assume its being reset. Maybe the int value (32 bit vs 16 bit?) is different in C# vs C++.

Also, the item.Pos's match, I tested them out already, ob1, ob2, and ob3 also all work, only conflict seems to be ob0.

C# code

``````var ob0 = (int)exe[item.Pos];
var ob1 = (int)exe[item.Pos + 1];
var ob2 = (int)exe[item.Pos + 2];
var ob3 = (int)exe[item.Pos + 3];``````

C++ code

``````int ob0 = (int)exe[item.Pos];
int ob1 = (int)exe[item.Pos + 1];
int ob2 = (int)exe[item.Pos + 2];
int ob3 = (int)exe[item.Pos + 3];``````

Edited by MasterGberry: n/a

4
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by MasterGberry

what is exe ? Is that an array of char?

Yeah.

I made a temporary solution by creating a new int

and if the value of exe[item.Position] was negative, i took that #, added it to 256, and reset ob0, it works, but i still want to know how to fix this if possible. Would rather have a full solution, and not a temporary.

Edited by MasterGberry: n/a

I'm still not exactly sure what you are trying to do. Can you give me a full example and then we can possible show you a non temporary solution.

item.Pos is an int, and exe is a char array, basically this converts the chars into ASCII standard (from what I understood). So I am getting a few negative values for ob0, which I shouldn't be. So observing the #s, if i was supposed to get 176, I was getting -80 instead. So i made temp below, and if ob0 was negative, I used the fact that the wrong # + 256 was going to give me the correct #. Then would take temp and assign it to ob0. It works, but I want to know why the original way wasn't workign :)

``````int ob0 = (int)exe[item.Pos];
int ob1 = (int)exe[item.Pos + 1];
int ob2 = (int)exe[item.Pos + 2];
int ob3 = (int)exe[item.Pos + 3];

if (ob0 < 0)
{
int temp = 256 + ob0;
ob0 = temp;
}``````

Char can be signed, or unsigned, it is implementation defined. Obviously in your compiler char is signed.

How is the char being initialized?

Where tokens2.at(0) is a hex address that is being converted to an int.

``````int Ps;
sscanf_s(tokens2.at(0).c_str(), "%x", &Ps);
item->Pos = Ps;``````
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.