Arduino - convert int to byte array[16] - RFID write data

Hello guys … !
my issue is i want to place this code :
<<
byte number[16] = {“100”};

with something like this
<<
int var = 100;
byte number[16] = {var};

Note:i’m new with arduino ! and also my english is not good
thank you for helping … !

An int in arduino is only 2 bytes. How are you gonna fit it into a 16-bytes array?

Try this:

  int var = 100;
  char number[16];

  sprintf(number, "%d", var);
byte number[16] = {"100"};

Declares and initialises an array of 16 bytes the first 3 of which contain the numbers 49, 48 and 48 respectively which is the ASCII representation of the digits

int var = 100;
byte number[16] = {var};

Declares and initialises an array of 16 bytes the first 3 of which contain 100, 0 and 0 respectively (if declared globally) and 100 in the first and random values if declared in a function

What is it exactly that you are trying to do ?

Actually i'm working with RFID !
the principe is i want to read data from the card (which return an int value), and for each use of the card i want to decrement the value by 1 until 0 .
the probleme is i can't parse the int value '100' to the byte number[16] . :frowning:

thank you guys ... ! the problem is solved thanks to Jimmus !
i appreciate your help so much ! thank you again !

the probleme is i can't parse the int value '100' to the byte number[16] .

Firstly '100' is not the same as "100"

If you receive "100" as an array of chars terminated by a zero (ie a C string) then you can convert it to a number using the atoi() function

void setup()
{
  Serial.begin(115200);
  char charNumber[] = {"100"};
  int intNumber = atoi(charNumber);
  Serial.println(intNumber--);
  Serial.println(intNumber);
}

void loop()
{
}