• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

binary conversion

New Here ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

Im having a problem with this code to convert decimal to binary ive got the formula but it wont print to the screen_txt only on the console and also my calculator wont let me change any other number other than 3 so if i press 7 binary should be 111 but it stays 11...


var num: Number;

var inputVal:Number;

var calculatedVal:Number;


binary_btn.addEventListener(MouseEvent.CLICK, binaryBtn);


function binaryBtn(event:MouseEvent) : void

{

inputVal = Number(screen_txt.text);

var num:Number = parseInt (, 10);

trace (num.toString(2));

trace(inputVal);

calculatedVal = Number(num);

screen_txt.text = calculatedVal.toString();

}

TOPICS
ActionScript

Views

611

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advocate ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

so it prints correctly to the console but doesn't display correctly inthe textfield?

it the textfield big enough to display the whole number?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

use:


var num: Number;

var inputVal:Number;

var calculatedVal:Number;


binary_btn.addEventListener(MouseEvent.CLICK, binaryBtn);


function binaryBtn(event:MouseEvent) : void

{

screen_txt.text =Number(screen_txt.text).toString(2)

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

function binary(event:MouseEvent) : void

{

          var num:Number = parseInt ("3", 10);

          trace (num.toString(2));

          output_txt.text =Number(output_txt.text).toString(2)

}

this basically converts decimal 3 into binary 11

and shows it on console

ive got my calculator and the display screen is output_txt and its not showing up on that

people have told me to use parseInt and trace but i have no idea how to go about it?? thats why i thought it might be similar to this

var num: Number;

var inputVal:Number;

var calculatedVal:Number;


binary_btn.addEventListener(MouseEvent.CLICK, binaryBtn);


function binaryBtn(event:MouseEvent) : void

{

        inputVal = Number(screen_txt.text);

        var num:Number = parseInt (, 10);

        trace (num.toString(2));

        trace(inputVal);

        calculatedVal = Number(num);

    screen_txt.text = calculatedVal.toString();

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 19, 2012 Mar 19, 2012

Copy link to clipboard

Copied

LATEST

use the code i suggested if you want the binary representation to display in screen_txt.  if you want it to display in a different textfield, replace screen_txt in my code with whatever.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines