Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

CString or BSTR Conversion Problem !!!

61 views
Skip to first unread message

news

unread,
Jul 10, 2002, 9:15:36 AM7/10/02
to
Hi, i have a problem of conversion,

in fact i have a CString or BSTR which contain "0x0f25g10" (an hexadecimal
value....) and i want catch into a int or int* value the real number
corresponding to an address in memory......

If you know a simple function in VStudio C++ 6.0 to do this

please mail me !!


Brett Levine

unread,
Jul 12, 2002, 10:09:31 PM7/12/02
to
Use the c function atol() to get your string value converted to a
32-bit numerical value, then use that value as a pointer, dereference
the pointer and you have your value in memory.

"news" <alexandr...@rd.francetelecom.com> wrote in message news:<aghc1p$gd...@news.rd.francetelecom.fr>...

r_z_...@pen_fact.com

unread,
Jul 15, 2002, 11:39:09 AM7/15/02
to
Will atol accept hexadecimal input?

On 12 Jul 2002 19:09:31 -0700, b...@firstpersonsoftware.com (Brett
Levine) wrote:

-----------------------------------------
To reply to me, remove the underscores (_) from my email address (and please indicate which newsgroup and message).

Robert E. Zaret
PenFact, Inc.
46 Beach Street
Boston, MA 02111
www.penfact.com

R.C.J. Bruning

unread,
Jul 15, 2002, 11:53:20 AM7/15/02
to
May be this could help???

ugly c-code.. but it could do the trick (not mine)

Hope it helped.

Greatings R.C.J. Brunning

This document provides a method to read hexadecimal numbers.
The atoi() function ignores the A-F digits in a hexadecimal
number. In fact, the first non-digit character in the string
passed to atoi() ends the conversion.
The following example converts a four-character text string that
represents a hexadecimal number into an integer. It can be used
as a template to create other ASCII-to-number conversions.
The example code defines a C\C++ function called axtoi() that
does the conversion. It includes a short main() that to test the
function.
#include
int axtoi(char *hexStg) {
int n = 0; // position in string
int m = 0; // position in digit[] to shift
int count; // loop index
int intValue = 0; // integer value of hex string
int digit[5]; // hold values to convert
while (n < 4) {
if (hexStg[n]=='\0')
break;
if (hexStg[n] > 0x29 && hexStg[n] < 0x40 ) //if 0 to 9
digit[n] = hexStg[n] & 0x0f; //convert to int
else if (hexStg[n] >='a' && hexStg[n] <= 'f') //if a to f
digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
else if (hexStg[n] >='A' && hexStg[n] <= 'F') //if A to F
digit[n] = (hexStg[n] & 0x0f) + 9; //convert to int
else break;
n++;
}
count = n;
m = n - 1;
n = 0;
while(n < count) {
// digit[n] is value of hex digit at position n
// (m << 2) is the number of positions to shift
// OR the bits into return value
intValue = intValue | (digit[n] << (m << 2));
m--; // adjust the position to set
n++; // next digit to process
}
return (intValue);
}
int main() {
char* test = "7fff";
cout << axtoi(test);
return 0;
}

<r_z_aret@pen_fact.com> schreef in bericht
news:3d32e78b...@nntp.theworld.com...

Gernot Frisch

unread,
Jul 17, 2002, 3:12:31 AM7/17/02
to
int hex = strtol("0xf34", "\0", 0x10);

HTH,
Gernot.


"news" <alexandr...@rd.francetelecom.com> schrieb im Newsbeitrag
news:aghc1p$gd...@news.rd.francetelecom.fr...

0 new messages