DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Hex to Integer Pls Helpp!!

1. Registered User
Join Date
Apr 2005
Posts
5

## Hex to Integer Pls Helpp!!

I don' t know anything about C/C++.
I have a data and a script. This script converts this data into X,Y coordinates and paints a graph...
I just need to know how this data converting...
I need to convert this data to create a graphic at php....
Can some one explain me this code?

My data is
80210021002100210022002300250025002600260026002700 28002B002C002E0030003100340036003A003F00420047004B 00500055005B00600068006F0078007F00880090009800A000 A900B100B900C100C900D000D700DE00E500EB00F000F700FC 01010105010A010F01140119011F012901390154018401DF02 7D0377

and my code is

void COrnekTakipElekroForez::GrafikYazdir()
{

if (GragikLog.IsEmpty())
return;

int FrantionCount = 0;
POINT Fraktion [10] ;

POINT apt [300] ;

int KY = 0;

CString Str;
Str.Format("%d",currsatir);

int j = 0;
int x = 150;

for (int i = 0; i < 1200 ; i = i + 4,j++)
{
CString Fraction = GragikLog.Mid(i,1);

int Y = BBHexToInt(GragikLog.Mid(i + 1,3));

//CETDEGIS_AFTBRS_OK
//apt[j].y = currsatir + 1200 - Y / 3;
apt[j].y = currsatir + 1450 - Y / 3;
//CETDEGIS_AFTBRS_OK
apt[j].x = x;
x = x + 7;

if (KY < apt[j].y)
KY = apt[j].y;

if (Fraction[0] == '8' || Fraction[0] == 'C')
{
Fraktion[FrantionCount].y = apt[j].y;
Fraktion[FrantionCount].x = apt[j].x;
FrantionCount++;
}
}

CPen pen;

pen.CreatePen(PS_SOLID, 0,RGB(0,255,0));
CPen* pOldpen = PSS->dc->SelectObject(&pen);

for (i = 0; i < FrantionCount;i++)
{
PSS->dc->MoveTo(Fraktion[i].x,Fraktion[i].y);
PSS->dc->LineTo(Fraktion[i].x,KY + 30);
}

if (FrantionCount > 0)
{
PSS->dc->MoveTo(apt[0].x,KY);
PSS->dc->LineTo(Fraktion[FrantionCount - 1].x,KY);
}

PSS->dc->SelectObject(pOldpen);

PSS->dc->LPtoDP(apt, 300) ;
PSS->dc->Polyline (apt, 300);

//PSS->dc->LPtoDP(Fraktion, 10) ;

}

int BBHexToInt(CString& sHex)
{
if(sHex.IsEmpty())
return 0;
int dgr = 0;

for(int i = sHex.GetLength() - 1,j =0; i >= 0;--i,++j)
{
double dgr0 = pow((double)16,(double)i);
int dgr1;
if(sHex[j] >= '0' && sHex[j] <= '9')
dgr1 = sHex[j] - '0';
else
dgr1 = 10 + sHex[j] - 'A';
dgr += ((int)dgr0 * dgr1);
}

return dgr;
}

2. Senior Member
Join Date
Dec 2003
Posts
3,366
How big is the hex data (does 4 'digits' = 1 integer? there is no space, no end of line, to seperate it) Also, if you insist on doing it by hand, you must handle the endian issue as the byte pairs are flipped on windows compatible processors (intel, amd, etc).

There is a way to use %x to just convert directly from hex-text to numbers, much as you have the %d. Look at the scanf family or figure out how to do it with cstring.

Your complete lack of comments combined with useless variable names and confusing code keeps me from trying to unravel what you did in that segment. I don't mean to be harsh, but that half page of code would take me a couple of hours to figure out because of the style.

3. Registered User
Join Date
Apr 2005
Posts
5
The data is 80210021002100210022002300250025002600260026002700 28002B002C002E0030003100340036003A003F00420047004B 00500055005B00600068006F0078007F00880090009800A000 A900B100B900C100C900D000D700DE00E500EB00F000F700FC 01010105010A010F01140119011F012901390154018401DF02 7D0377
I have no idea. I don' t the digit of them... I guess that It' s somewhere in the code...
When this data execute in this code can you simulate what will gonna happen?

4. Senior Member
Join Date
Dec 2003
Posts
3,366
Its going to print out meaningless output that you cannot tell anything about, because you don't know if its right or wrong. Can you make a single x/y pair in your original program and print that data here, something like (1000,16)?

5. Senior Member
Join Date
Dec 2003
Posts
3,366
Perhaps this simple, C style example will help somehow. But you STILL must know what the data file means or you will not get far.

#include<cstdio>
using namespace std;
int main()

{
char ch[] = "ff 10";
int hex, hey;
sscanf(ch, "%x %x", &hex, &hey);
printf("%i %i \n",hex, hey);
return 0;
}

6. Registered User
Join Date
Apr 2005
Posts
5
Dear friend,
I have solved my problem...
it' s coming as 4 digits like 8021 - 0021 ..... and goes on...
It seperates first digit... like 8 & 021 ... than It converts 021 to decimal... Because its Hex...
apt[j].y = currsatir + 1450 - Y / 3;
Y means hexdec("021")
So I have found the Y coordinate of the graphic... Then I applied same mental in my php code with ape chart component, I draw the graph...

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 FAQ Latest Articles Java .NET XML Database Enterprise