Serial Decimal to binary

Hello every one,

I’m some what new to arduino… This is my problem…

I am sending 8 set of decimal values to arduino via serial…

ex : < 102,103,108,130,023,45,66,123>

then I have to get each value separately and convert into binary value. Then call a function by parsing each binary value…

B_function(byte input)

// some calculations with input


I can separate each decimal value into integer format using int_numb = atoi(“string”) function…

But how can I convert it into binary ?? such as 102 = 1100110

There is a function - > String (102 , BIN) but this makes String variable which cant use to call the B_function()… Please someone help me… :o :o

Since all computer data is ultimately in binary, I’m assuming you want to display the decimal values in binary. Try this to see if it does what you want.

#define ARRAYELEMENTS(x) (sizeof(x) / sizeof(x[0]))   // Determine elements in an array

void setup() {

  int i;
  int vals[] = {102, 103, 108, 23};

  for (i = 0; i < ARRAYELEMENTS(vals); i++) {
    Serial.println(vals[i], BIN);


void loop() {


Hi econjack Thank you very much for the reply.... Actually I dnt wanted to display the binary values.. I wanted to use the binay values inside a function.... I had this problem due to lack of knowledge.. I though that I have to pass values in binary format when assigning to a Byte variable.. now I knw if the value of an integer is less than 256, it can assigned to byte variable...

This is what I thought Byte val = 0B00011 (I thought 0B00011 format is essential )

Now I know Byte val = val2 can be done ( val2 = 3)

Thanks again for your valuable time...

The third example in Serial Input Basics uses the same data format as in the Original Post and it includes a Parse example to illustrate how to convert the Ascii values to integers and floats.