Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

double to binary

 
tilly ross
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to read in a double value, as a reading from 32.0 to 44.0. I read this in from getaReading ( a text box) and this inputs ok. I want to then change it to a binary value to sent to another class to simulate a temperature input. 32.0 will be 00000001, then 1 bit added for each 0.1 value input. (00000000 will be an error of too low an input for anything below 32.0) I have got this far, but cannot find a way to change a double to a byte. Can anyone help me get any farther with my class? any pointers or advice would be appreciated

static final double steps = 0.1; // stores value between each step in temperature
static final double min = 32.0; // stores the minimum value

public void setConvertByte(double value){
value = inputTemp.getaReading();
byte[] input = new byte [00000000] ;
value = (value - min / steps);
input = byte(value);
}
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
not sure this is what you're after

double num = 33.3;
int toConvert = (int)(num*10) - 320;
System.out.println(Integer.toBinaryString(toConvert));
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic