Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

decimal to binary 1

Status
Not open for further replies.

ugly

Programmer
Jul 5, 2002
70
GB
I have a simple dialog box containing two edit boxes, If a decimal number is entered into the first box I would like for the equivalent binary value to appear in the second box.
 
You could do it this way:
The "Decimal-Edit box" should get a variable type 'int',
the other type 'CString'.
When a button is clicked (or another message of your choice), do this:
Code:
void CYourDialog::OnMessage()
{
  UpdateData();
  char buffer[20]; //20 could take numbers up to 2^18(+\0)
  _itoa(decimal_variable, buffer, 2)//2 indicates binary
  strBinaryVariable= buffer;
  UpdateData(FALSE);
}
This works; but it is not a very good code.
Eg. you have to look out that the decimal value is not negative etc.
 
many thanks that works just fine for what I need
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top