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
Joined: Jun 09, 2003
Posts: 4632
posted
0
not sure this is what you're after
double num = 33.3; int toConvert = (int)(num*10) - 320; System.out.println(Integer.toBinaryString(toConvert));
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.