Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Adding array bytes

Status
Not open for further replies.

SwingeyP

Member
I have a situation where I am reading data from a serial port and storing it in an array.

The data is a GPS coordinate. The array will look something like this.

array(0) = 5
array(1) = 2
array(3) = 5
array(4) = 6
array(5) = 2
array(6) = 1

and so on.

I want to make 1 number (525621) so I have one variable that is 525621 ( a long?) It may not be necessary for the last digit accuracy so perhaps it will fit in a word.

How do I do it?

Regards - Paul
 
number = array(0)*100000
number = number + array(1)*10000
number = number + array(2)*1000
number = number + array(3)*100
number = number + array(4)*10
number = number + array(5)
 
Alternatively,
Code:
number=0;
For(i=0;i<6;i++)
    number=number*10+array(i);

Mike.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top