BYTE GetByte(char* sBuf, int& index)
    int t_index = index;
    return (BYTE)(*(sBuf+t_index));

int GetShort(char* sBuf, int& index)
    index += 2;
    return *(short*)(sBuf+index-2);

and i cannot convert this

Recommended Answers

All 5 Replies

In C# you have the Convert class which uses specific conversions to many different type of data. Here's the MSDN library article on it Click Here

Thanks for reply, so GetByte reading bytes from server/client packet not convert,
Byte size 2, Short size 4, DWORD size 8
String size comin with packet

Simple packet : 15 + D75EBC0F + 5811

char *pBuff = 15D75EBC0F5811 
Byte Val1 = GetByte(pBuff, index);
DWORD Val2 = GetDWORD(pBuff, index);
Short Val3 = GetShort(pBuff, index);

I think this will do the trick DWORD is 32-bit unsigned integer, short is signed 16-bit integer. I assumed that all the values are in Hexadecimal, thus the ',16' in the parameter list of the convert functions. Take that out for any that are decimal or change it to the proper value of whatever the base is(

    string packet = "15D75EBC0F5811"
    byte val1 = Convert.ToByte(packet.substring(0,2),16)
    uint32 val2 = Convert.ToUint32(packet.substring(2,8),16)
    int16 val3 = Convert.ToInt16(packet.substring(10),16)

Some of my syntax might not be 100%, I'm doing this off the top of my head.

commented: Thanks !! Nice Logic !! +0

It's well done so thanks bro, please add me

Sorry not a big facebooker. Don't forget to mark this solved thx.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.