RF_Developer
Joined: 07 Feb 2011 Posts: 839
|
Re: how to Split 16bit value into 16 1bit value. |
Posted: Tue Aug 27, 2013 6:14 am |
|
|
veerabahu wrote: | Can anyone point me in the right direction for building a function to split a 16bit value into 16 1bit values then reassembling them again? For instance I have an integer of say 5423 I need to split that into to 1bit values. Im going to then send them through Modbus Reg to another PIC then reassemble the value once recieved. |
You don't have to. MODBUS has registers, so-called "input registers" and "holding registers", which are all 16 bit, as well as single bit "coils".
If you still want to split out each bit of a value then you can shift the bits using >> or << depending on whether you want to transmit the most significant bit first, then send the top bit and use <<, or the least significant bit, in which case send the lowest bit and use >>. Another way is to have a single bit mask that you use to and with the data and then shift the mask left or right as you need. |
|