Pages: [1]   Go Down
Author Topic: Converting Binary from a Sensor into decimal  (Read 899 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have a temperature sensor which will be presenting data in the serial monitor.

To convert from the raw data the eqn is as follows:

T = C x 2n

C = the sensor output in decimal ( the output is a 9bit and I have it in the form of a 16 bit integer)
n is defined by what resolution you are getting from the sensor ( 9, 10, 11, 12) in my case n = -1

My question is this how do I convert my integer "temp" into a decimal to then use in this formula.

Thanks
« Last Edit: December 12, 2012, 07:04:15 pm by Richard_N » Logged

Global Moderator
Dallas
Offline Offline
Shannon Member
*****
Karma: 210
Posts: 13039
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset


T = C * 0.5
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That will multiply the binary value by 0.5 though, do I not need to convert it to decimal first?
Or does the later serial print do that for me?

Thanks
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12630
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Decimal is a way of representing a number textually, it is not an attribute of the integer value. If you have the temperature value as a 16-bit integer as you say, then you need simply multiply it by your constant (2^-1) to get the result. And that calculation is not going to be too complicated.
« Last Edit: December 12, 2012, 07:16:09 pm by PeterH » Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
God Member
*****
Karma: 19
Posts: 785
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

A number is a number whether you write it in binary or decimal or whatever.  To humans it is different.  To mathematical operations it is not. 

In decimal, 2 * 2 = 4

In Binary  10 * 10 = 100

In roman numerals  II * II = IV

There's no difference in any of it as far as the mathematical operation is concerned. A computer can only use binary representations no matter what.  Save converting to decimal until you have something you want to show to a human. 
Logged

Pages: [1]   Go Up
Jump to: