# convert 10 bits to 8 bits

Started by March 20, 2006
```i am attempting to add memory using an external eeprom.  the good
news is that i have added the memory and know that it works.  the bad
news is i can't get my information onto the memory.

the problem is i am reading data from an imu using the command
GetADC(pinnumber), which returns an analog voltage in 10 bits.
to log our information onto external memory i am using the command
ShiftOut, which can only shift a max of 8 bits of data.  just to see
what happens, i used cbyte(getadc(pinnumber)), and this did not
work.  i am wondering whether there was a way to convert the 10 bit
voltage to 8 bit, or maybe there is an different way to send the
information to the external memory other than using shiftout. Maybe i
can get our analoge voltage in 8 bits instead of 10 bits using a

steven rauseo
```
```> ... to convert the 10 bit voltage to 8 bit...

GetADC produces an integer that contains the 10-bit conversion.  To
convert that integer to a byte means you will lose two bits of significance:

bValue = cByte((GetADC(n) + 2) \ 4)

+ 2 is for rounding.

You can keep the original 10-bits of resolution by keeping the sample as
an integer.  That means you'll need to write two bytes per integer and
reassemble them into integers later.  There are several methods to do
that.  Here's one:

When you read the two bytes back, you can reassemble them into an integer:

iValue = cInt(bMSB) * 256 + cInt(bLSB)
Tom
```
```> ... to convert the 10 bit voltage to 8 bit...
GetADC produces an integer that contains the 10-bit conversion.  To
convert that integer to a byte means you will lose two bits of
significance:

bValue = cByte((GetADC(n) + 2) \ 4)

+ 2 is for rounding.

You can keep the original 10-bits of resolution by keeping the sample
as an integer.  That means you'll need to write two bytes per integer
and reassemble them into integers later.  There are several methods to
do that.  Here's one: