473,507 Members | 12,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

hex string conversion to integer

32 New Member
Yes 6.0

I am using code similar to this:
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2.  #include <stdio.h>
  3.  
  4.  int main(void)
  5.  {
  6.  char string[] = "0D76";
  7.  long value = strtol(string, NULL, 16);
  8.  printf("value of '%s' is %ld\n", string, value);
  9.  return 0;
  10.  }
  11.  
I have this application running in VS2015 but cannot get it to output an executable that will run on an old 32bit XP computer that the owner doesn't want to upgrade.
Thus I'm on VS6.0

strtol requires a
char string[] as its first argument.
all of my data is being passed in, in a huge array of records declared
std::string hexdata[250000];
How do I get around this? This VS6 environment doesn't really have streams to implement.
Also, when I look in the VS include directory all the standary headers are there including stdlib.h
The compiler an error that strtol is not a member of std.
I have opened stdlib.h and I find strtol listed in there.
Any clues on how to get it to see strtol in stdlib.h or is there another workaround giving my above constraints.
Thanks
Sep 15 '15 #1
7 2078
weaknessforcats
9,208 Recognized Expert Moderator Expert
I don't know how VS2015 is packaged but this code compiles and links just fine using VS2013.

I'd like to see the error. strtol has never been part of std since it's part of C and std applies only to C++.
Sep 15 '15 #2
emp
32 New Member
Ok, there is the exact block of code that I am using:
Expand|Select|Wrap|Line Numbers
  1. std::string hold =   text[i].substr(2, 1);
  2. std::cout << "hold = " << hold << std::endl;    
  3. int byte_count  = std::strtol(hold, &ptr, 16);
  4.  
and here are the errors:

file_operations.cpp
c:\program files\microsoft visual studio\myprojects\rcmprogramming\file_operations.c pp(112) : error C2039: 'strtol' : is not a member of 'std'
c:\program files\microsoft visual studio\myprojects\rcmprogramming\file_operations.c pp(112) : error C2664: 'strtol' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const
char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

RCMprogramming.exe - 2 error(s), 0 warning(s)
Sep 16 '15 #3
emp
32 New Member
If I remove the std:: from before strtol I get this error which I cant beat either

c:\program files\microsoft visual studio\myprojects\rcmprogramming\file_operations.c pp(111) : error C2664: 'strtol' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'const
char *'
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.

RCMprogramming.exe - 1 error(s), 0 warning(s)

Remember that the data comes to this function in the form of an array declared:
std::string hexdata[250000];

Here is a representative line of data:

:800C020000000011111111000000000000000000000000000 00000000000001111111100000000000000000000000011111 11100000000040404040404040404040404F6F6F6F6E8E8E8E 80000000000000000151515150404040404040404000000001 11111110404040404040404000000000404040404040404151 515154040404004AE

Once I get through the header bytes then I grab 2 bytes at a time and convert it to integer.
Sep 16 '15 #4
weaknessforcats
9,208 Recognized Expert Moderator Expert
I see what's happening.

Some nutcase has written a function that works like strtol but which takes an std::string as an argument. Then the function was named strtol. To avoid a name collision, the function was put in the std namespace. This violates namespace rules since std is reserved for C++ library items. It also violates the rule that you don't name your functions with the same name as system functions.

You need to find this code.
Sep 16 '15 #5
emp
32 New Member
I managed a fix.

const * temphold;

then

temphold = hold.c_str();
int byte_count = strtol(temphold , &ptr, 16);

This correctly decodes the two bytes in temphold to the correct decimal value.
Sep 16 '15 #6
weaknessforcats
9,208 Recognized Expert Moderator Expert
Probably you don't need temphold:

Expand|Select|Wrap|Line Numbers
  1. int byte_count = strtol(hold.c_str() , &ptr, 16);
  2.  
I would certainly go through and remove all std::strtol calls. The confusion factor should be obvious.
Sep 16 '15 #7
emp
32 New Member
Certainly, and thanks
Sep 16 '15 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
2175
by: John van Terheijden | last post by:
Hi. I'm trying to make a conversion algorithm that colors even and odd words in a HTML string with <div> tags. // input text with all sorts of HTML tags and whitespace $str = "<h1>Title...
3
3719
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
3
27543
by: news.hku.hk | last post by:
could you tell me how can i convet a string to integer?? #include <iostream> #include <string> using namespace std; int main(){ int integer; string buffer("123456789");
8
424
by: alex | last post by:
i have a string "dasfk" stored in a variable of type string and i want to convert it to const _bstr_t, anybody know? Posted Via Usenet.com Premium Usenet Newsgroup Services...
18
34069
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
5
3413
by: Allerdyce.John | last post by:
Do I need to convert string to integer in python? or it will do it for me (since dynamic type)? In my python script, I have this line: x /= 10; when i run it, I get this error: TypeError:...
9
2717
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string froma file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
3
9174
by: priyanka | last post by:
Hi there, I want to convert a String into integer. I get the string from a file using : string argNum; getline(inputStream,argNum); I now need to convert argNum into integer.
2
4953
by: Saeed Amrollahi | last post by:
Dear All Hi I usually use the following function for built-in types to std::string conversion: // convert a type (typically built-in type) to std::string template<class T> inline std::string...
11
6118
by: luftikus143 | last post by:
Hi there, gush, frustrating. I am not a pro; but I know PHP well enough to understand how it works. And a simple conversion from string to integer via (int)$value or intval($value) should be...
0
7109
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7313
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
5619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5039
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3190
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1537
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
758
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
411
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.