PDA

View Full Version : Accessing a 9 bit number from two bytes



Radiance
- 9th June 2005, 15:22
[doh!] This should probably be posted in the General area[/doh!]

I have a device that outputs a string of data that I read in a pic and have to output a number to an LCD that is in the range of 0-512 (9 bits). The serial stream is read like this:
<pre>
serin XpodRX,2,1800,NoRx,oxdata1,oxdata2,spo2
</pre>
The problem is, only the first 7 bits of oxdata2 are the number i need. The other two bits are the first two bits of oxdata1. The way I'm doing it now appears extremely ineficient, and takes up a lot of code space, which I need. Can someone maybe give me a pointer on a cleaner way to do this?


Here's how I calculate the number I need:
<pre>
if oxdata1.1 and 1 then
numout= numout+ 256
endif

if oxdata1.0 and 1 then
numout= numout+ 128
endif

if oxdata2.6 and 1 then
numout= numout+ 64
endif

if oxdata2.5 and 1 then
numout= numout+ 32
endif

if oxdata2.4 and 1 then
numout= numout+ 16
endif

if oxdata2.3 and 1 then
numout= numout+ 8
endif

if oxdata2.2 and 1 then
numout= numout+ 4
endif

if oxdata2.1 and 1 then
numout= numout+ 2
endif

if oxdata2.0 and 1 then
numout= numout+ 1
endif
</pre>

Ingvar
- 9th June 2005, 17:35
NumOut = Oxdata2 & %01111111
NumOut.7 = Oxdata1.0
NumOut.8 = Oxdata1.1

..... is one way of doing it.