While I collect the two data from I2C,
If perform by C, my code is like the following
short a = 0;
short b = 0;
try
{
a = Convert.ToInt16(recvbuf[1] << 8);
b = Convert.ToInt16(recvbuf[2]);
}
catch(Exception err)
{
Debug.Print(err.Message);
}
float c = (a + b) / (float)10;
DCLabel.Text = c.ToString();
however, i cannot see any signed 16bits operation or conversion tools in
ARMbasic.Anybody know How to do the same in ARMbasic.
16bit signed integers
-
YahooArchive
- Posts: 1462
- Joined: Fri Oct 19, 2012 5:11 am
Re: 16bit signed integers
> a = Convert.ToInt16(recvbuf[1] << 8);
> b = Convert.ToInt16(recvbuf[2]);
> DCLabel.Text = c.ToString();
Variables and arithmetic in ARMbasic are done with 32 bit signed integers. A 16
bit integer is a subset of that, and would remain unsigned with shift operations
as long as 0 is shifted into the 32bit MSB.
To convert to a string (ASC in VB) is done automatically (see help files for ASC
and other string functions)
DIM TEXT(20) AS STRING
TEXT = 1234 ' automatic conversion to string
> b = Convert.ToInt16(recvbuf[2]);
> DCLabel.Text = c.ToString();
Variables and arithmetic in ARMbasic are done with 32 bit signed integers. A 16
bit integer is a subset of that, and would remain unsigned with shift operations
as long as 0 is shifted into the 32bit MSB.
To convert to a string (ASC in VB) is done automatically (see help files for ASC
and other string functions)
DIM TEXT(20) AS STRING
TEXT = 1234 ' automatic conversion to string