# Unsigned Long to Array

**URL:** <https://forum.arduino.cc/t/unsigned-long-to-array/1336645>\
**Category:** General Guidance\
**Created:** [December 28, 2024, 5:01pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645 "2024-12-28T17:01:23Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 5:01pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/1 "2024-12-28T17:01:24Z")

</div>

Hello everyone,

This is a very simple request,  
with an Arduino UNO,

Is it possible to convert each number of a unsigned long to an array

```arduino
From:
unsigned long var = 4294967295;

To:
array[0] = 4
array[1] = 2
array[2] = 9
array[3] = 4
array[4] = 9
array[5] = 6
array[6] = 7
array[7] = 2
array[8] = 9
array[9] = 5

```

Thanks

---

<div class="post-metadata">

**Author:** ![Dave\_Lowther](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dave_lowther/32/1092885_2.png) [@Dave\_Lowther](https://forum.arduino.cc/u/Dave_Lowther)\
**Post date:** [December 28, 2024, 5:26pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/2 "2024-12-28T17:26:02Z")

</div>

> [@jackcable2002](#):
>
> Is it possible to convert each number of a unsigned long to an array

Yes. Here is one way to do it

```arduino
unsigned long var1 = 4294967295;
byte numbers[10];

void setup() {
  Serial.begin(115200);
  convertUlToArray(var);
  printResults();
}

void loop() {
}

void convertUlToArray(unsigned long input) {
  for (int i = 9; i >= 0; i--) {
    numbers[i] = input % 10;
    input = input / 10;
  }
}

void printResults() {
  Serial.print(F("Unsigned long = "));
  Serial.println(var);
  Serial.print(F("Array contents = "));

  for (byte i = 0; i < 10; i++) {
    Serial.print(numbers[i]);
  }
  Serial.println();
}

```

Serial monitor output

```arduino
Unsigned long = 4294967295
Array contents = 4294967295

```

---

<div class="post-metadata">

**Author:** ![LarryD](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/larryd/32/215550_2.png) [@LarryD](https://forum.arduino.cc/u/LarryD)\
**Post date:** [December 28, 2024, 5:26pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/3 "2024-12-28T17:26:34Z")

</div>

- In the end, what are you trying to.

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 5:47pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/4 "2024-12-28T17:47:17Z")

</div>

Many thanks Dave  
I had to edit 'var' to 'var1'  
it's working fine.  
since there's no array function to convert long, double, etc..  
this will work

```arduino
unsigned long var1 = 4294967295;
byte numbers[10];

void convertUlToArray(unsigned long input) {
  for (int i = 9; i >= 0; i--) {
    numbers[i] = input % 10;
    input = input / 10;
  }

```

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 5:51pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/5 "2024-12-28T17:51:52Z")

</div>

Hello LarryD,  
I was looking for a way to convert long,double etc.  
since the array sample code from Arduino can't do this.  
Thanks

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 28, 2024, 5:59pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/6 "2024-12-28T17:59:51Z")

</div>

Why do you need this ?  
Are you trying to get a text representation?

The modulo approach won’t work for a double and nor sure this is what you need for a negative number

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 6:06pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/7 "2024-12-28T18:06:12Z")

</div>

my mistake just for long.  
thanks

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 6:07pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/8 "2024-12-28T18:07:30Z")

</div>

Dave gave me the right answer for long var,

Thanks again Dave.

---

<div class="post-metadata">

**Author:** ![Dave\_Lowther](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dave_lowther/32/1092885_2.png) [@Dave\_Lowther](https://forum.arduino.cc/u/Dave_Lowther)\
**Post date:** [December 28, 2024, 6:07pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/9 "2024-12-28T18:07:48Z")

</div>

> [@jackcable2002](#):
>
> I had to edit 'var' to 'var1'

Sorry, after I ran it, I started editing the sketch to print out a few different examples of values in unsigned longs, with var1, var2, etc. Then decided not to bother doing that, but pasted the edited code which I obviously didn't compile before posting it.

> [@jackcable2002](#):
>
> since there's no array function to convert long, double, etc..

Ah, I just did something that worked for unsigned long. I didn't know you also wanted to convert other numeric types. Perhaps try converting to a String and then step along the characters in the string to get the number corresponding to each character.

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 6:11pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/10 "2024-12-28T18:11:46Z")

</div>

Hello Dave,  
you did an excellent job, I'm a very beginner to Arduino and I did mention double,  
but for what I'm working now the Long, will do the work fine.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 28, 2024, 6:36pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/11 "2024-12-28T18:36:17Z")

</div>

> [@jackcable2002](#):
>
> just for long.

Unsigned ? (As per the title)

I’m curious why you need this

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 7:27pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/12 "2024-12-28T19:27:42Z")

</div>

Hello J-M-L  
for now I'm learning Arduino code, and read about array in general  
I dont have a specific project just learning.  
I could have ask for 'int' instead.  
Have a great day.

---

<div class="post-metadata">

**Author:** ![J-M-L](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j-m-l/32/766245_2.png) [@J-M-L](https://forum.arduino.cc/u/J-M-L)\
**Post date:** [December 28, 2024, 7:47pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/13 "2024-12-28T19:47:56Z")

</div>

An int is like a long, it’s signed so what do you expect in your array for -123456 ?

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 7:50pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/14 "2024-12-28T19:50:25Z")

</div>

Hello Dave,  
I tried to find info's about this line 'void convertUlToArray(unsigned long input)'  
did not find anything about 'input' or function related.  
if possible, can you direct me to a source that I can learn from it.  
Thanks again Dave.

---

<div class="post-metadata">

**Author:** ![jackcable2002](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jackcable2002/32/1013044_2.png) [@jackcable2002](https://forum.arduino.cc/u/jackcable2002)\
**Post date:** [December 28, 2024, 8:05pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/15 "2024-12-28T20:05:21Z")

</div>

Just found :  
([C++ Function (With Examples)](https://www.programiz.com/cpp-programming/function))

---

<div class="post-metadata">

**Author:** ![Dave\_Lowther](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dave_lowther/32/1092885_2.png) [@Dave\_Lowther](https://forum.arduino.cc/u/Dave_Lowther)\
**Post date:** [December 28, 2024, 8:06pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/16 "2024-12-28T20:06:56Z")

</div>

> [@jackcable2002](#):
>
> Just found

Yes, it's a function.

---

<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:** [June 26, 2025, 8:07pm UTC](https://forum.arduino.cc/t/unsigned-long-to-array/1336645/17 "2025-06-26T20:07:14Z")

</div>

Closed on June 26, 2025, 8:07pm UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
