to concatenate uint8_t variables

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

to concatenate uint8_t variables

1,467 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by nasib on Thu Jan 10 11:39:43 MST 2013
Hi all!

I am using the lpcxpresso 11u14 and i'm trying to concatenet two uint8_t, in order to create an uint16_t.


I have these two variables in an array: (data[0] = uint8_t) (data[1] = uint8_t). Actually i want to convert "data" in an uint16_t.

Anyone knows how could i do it ?

thank you very much!
Labels (1)
0 Kudos
Reply
1 Reply

1,313 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jmf75 on Thu Jan 10 14:14:46 MST 2013
You mean something like that

First method:
<code>
uint16_t locsh_Val= *((uint16_t*)data);
</code>

Second method:
<code>
  typedef union _t_MyUnion
{
  uint16_t Data16;
  uint8_t  Data[2];
} t_MyUnion;

  t_MyUnion loc_Union;
  loc_Union.Data[0]=0xAA;
  loc_Union.Data[1]=0x55;
 
  uint16_t locsh_Val=loc_Union.Data16;   //locsh_Val == 0x55AA
</code>
0 Kudos
Reply