Questions tagged [strtoull]
19 questions
8
votes
1 answer
Output of strtoull() loses precision when converted to double and then back to uint64_t
Consider the following:
#include
#include
int main() {
std::cout << std::hex
<< "0x" << std::strtoull("0xFFFFFFFFFFFFFFFF",0,16) << std::endl
<< "0x" << uint64_t(double(std::strtoull("0xFFFFFFFFFFFFFFFF",0,16)))…

Adama
- 720
- 2
- 5
- 23
4
votes
1 answer
Does strtoull always return a valid number or set errno?
Is strtoull guaranteed to either return a valid number, or set errno (if no valid number could be parsed)?
In other words, is this
errno = 0;
n = strtoull(s, 0, 10);
if (errno) {
perror(s);
exit(1);
}
// do something with n
correct, or is some…

rwallace
- 31,405
- 40
- 123
- 242
4
votes
1 answer
Surprising behavior of strtoull("-1", NULL, 0) and other negative values
strtoull("-1", NULL, 0) evaluates to 18446744073709551615, (0xFFFFFFFFFFFFFFFF aka ULLONG_MAX) on the systems I tested (OS/X with Apple Libc, Linux with Glibc).
Since strtoull is supposed to check for values out of the range of the return type, why…

chqrlie
- 131,814
- 10
- 121
- 189
2
votes
1 answer
strtoul() not working as expected?
I am trying to convert a string such as "0x7ffd01767a60" to hexadecimal so I can compare pointers. Not sure if this is the best decision.
I am doing this:
char *address = "0x7ffd01767a60";
strtol(address,NULL,16);
…

deko
- 463
- 1
- 6
- 17
1
vote
3 answers
Check if a string representing float/unsigned int is too big
I have a file containing strings representing float and uint64_t values.
I know exactly which string contains float values and which contains uint64_t values - that is not the problem I'm facing.
Here is how I convert them to their respective…

stht55
- 390
- 1
- 8
1
vote
2 answers
stroll, strol functions not giving correct output for long_min
For the following code
#include
using namespace std;
int main()
{
bitset<64>b(numeric_limits::min());
string s=b.to_string();
char *ptr=new char [s.size()+1];
strcpy(ptr,s.c_str());
long l1=strtol(ptr,NULL,2);
…

duplex143
- 619
- 2
- 9
- 25
1
vote
3 answers
How to parse a string containing an integer and check if greater than a maximum in c++
I want to determine (in c++) if a string contains a number that is in the range 0 - UINT_MAX
I have tried atoi etc but that don't handle this case.
For example the string 42949672963 would fail the test
Has anyone got any suggestions?

Gunner
- 125
- 10
1
vote
1 answer
C: Convert string to unsigned long long Error
I'm simply trying to convert a String (readed from a line in a file) in a long long variable. My problem is that i get Segmentation Fault, and I don't know why... Here's the code: (I put a comment on the error on the "3° Call" function)
#define…

Lorenzo
- 85
- 1
- 9
1
vote
1 answer
memory leak in strtoull() call in Hamming Distance calc
I am calling strtoull() over 100 million times in my command line Objective-C OS X app calculating Hamming distance. I have tracked down a ~30 byte/call memory leak to this function call from ph_hamming_distance(). I have looked at the BSD source…

rick
- 51
- 6
0
votes
1 answer
strtoull() Availbility in C89
I have been reading through the documentation for strtoul()/strtoull() from here, and under the "Conforming To" section towards to bottom, it makes these two points:
strtoul(): POSIX.1-2001, POSIX.1-2008, C89, C99 SVr4.
strtoull(): POSIX.1-2001,…

cpchristensen
- 28
- 3
0
votes
1 answer
Why first two digits are lost after using left-shift bitwise operator?
I am storing a hexadecimal value in a uint64_t variable. When I call strtoull() to convert the string to a hexadecimal value I get the correct result, but when I do a left-shift (<<) by 32 I am losing the first two digits.
The string I am testing is…

Juhi
- 1
- 2
0
votes
1 answer
strtoull use properly in C
So I have a string like this:
char numbers[] = "123,125,10000000,22222222222]"
This is an example, there can be lots more of numbers in the array but it will certainly end with a ].
So now I need to convert it to an array of unsigned long longs.
I…

fangio
- 1,746
- 5
- 28
- 52
0
votes
2 answers
If statement executes even when condition is false
if( (*ptr != ',') || strlen(ptr+1) < sizeof(struct A) * num1)
{
printf("\n Condition satisfied.");
}
This is the code in question. I have a string of the format str = "-1,ABCDEFGH", and a struct A of size 15 bytes.
I'm performing this…

user3041117
- 9
- 1
0
votes
1 answer
token to unsigned printing odd values
As the title suggested I am getting some weird returns from strtoul, I have tested just by using strcpy to store the data as a string and it is giving the correct value, but as soon as I try and change it to an unsigned int by using strtoul() I am…

Rory Thoman
- 69
- 12
0
votes
1 answer
strtoull "seems" to return a wrong value
Basically I am trying to convert hex strings into unsigned long long values using strtoull. Here's the simple code
#include
#include
int main ()
{
unsigned long long val =0;
//printf("sizeof(unsigned long long)=%d\n",…

Pavan Manjunath
- 27,404
- 12
- 99
- 125