# using unsigned long error

**URL:** <https://forum.arduino.cc/t/using-unsigned-long-error/355824>\
**Category:** Programming\
**Created:** [January 1, 2016, 4:31pm UTC](https://forum.arduino.cc/t/using-unsigned-long-error/355824 "2016-01-01T16:31:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![a55830](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/a55830/32/219739_2.png) [@a55830](https://forum.arduino.cc/u/a55830)\
**Post date:** [January 1, 2016, 4:31pm UTC](https://forum.arduino.cc/t/using-unsigned-long-error/355824/1 "2016-01-01T16:31:44Z")

</div>

Hi  
im trying to convert HEX to Decimal....

```cpp
unsigned long cAll1 = strtol(BABB97AE, NULL, 16);

```

BUT , BABB97AE = 3132856238 what i get is 2147483647 and that is the max og "long" that is why i use unsigned that should hold 4294967295 and that is fine....

info from Arduinos own page [unsigned long](https://www.arduino.cc/en/Reference/UnsignedLong)

---

<div class="post-metadata">

**Author:** ![anon94801460](https://avatars.discourse-cdn.com/v4/letter/a/278dde/32.png) [@anon94801460](https://forum.arduino.cc/u/anon94801460)\
**Post date:** [January 1, 2016, 4:45pm UTC](https://forum.arduino.cc/t/using-unsigned-long-error/355824/2 "2016-01-01T16:45:50Z")

</div>

Use strtoul() instead.

---

<div class="post-metadata">

**Author:** ![holmes4](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/holmes4/32/215302_2.png) [@holmes4](https://forum.arduino.cc/u/holmes4)\
**Post date:** [January 1, 2016, 5:23pm UTC](https://forum.arduino.cc/t/using-unsigned-long-error/355824/3 "2016-01-01T17:23:10Z")

</div>

First,

You don't convert from dec to hex or anything else!

You represent a number in deimal/Hex so

A is the number ten when written in Hex. But we do not write it simply as A we write 0xA the 0x tell us and the compiler that we have written the number in hex.

There is no such thing as a decimal number or a hex number there is only the number. We write/represent numbers in decimal or hex or ........ formats.

Second,

Strings are always written using double quotes eg "a string"

So you should just have written

```cpp
unsigned long cAll1 = 0xBABB97AE;

```

If you do want to use any of the strXXX functions in a case like this (and I can't see why you would) then you must use the double quotes ie "BABB97AE".

BABB97AE is just an identifier (a variable name) it is not the hex representation of a number.

Mark

---

<div class="post-metadata">

**Author:** ![a55830](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/a55830/32/219739_2.png) [@a55830](https://forum.arduino.cc/u/a55830)\
**Post date:** [January 1, 2016, 9:32pm UTC](https://forum.arduino.cc/t/using-unsigned-long-error/355824/4 "2016-01-01T21:32:56Z")

</div>

@jremington

thx for that it worked great

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 9:39pm UTC](https://forum.arduino.cc/t/using-unsigned-long-error/355824/5 "2021-05-05T21:39:13Z")

</div>

Closed on May 5, 2021, 9:39pm UTC


