Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
The moose likes Swing / AWT / SWT and the fly likes double to binary Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Badass: Making Users Awesome this week in the Game Development forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "double to binary" Watch "double to binary" New topic

double to binary

tilly ross

Joined: Oct 13, 2005
Posts: 1
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
not sure this is what you're after

double num = 33.3;
int toConvert = (int)(num*10) - 320;
I agree. Here's the link:
subject: double to binary