Skip navigation
adamkay123
Currently Being Moderated

binary conversion

Mar 19, 2012 6:46 AM

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();

}

 
Replies
  • Currently Being Moderated
    Mar 19, 2012 7:20 AM   in reply to adamkay123

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

     

    it the textfield big enough to display the whole number?

     
    |
    Mark as:
  • kglad
    72,207 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 19, 2012 7:26 AM   in reply to adamkay123

    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)

    }

     
    |
    Mark as:
  • kglad
    72,207 posts
    Jul 21, 2002
    Currently Being Moderated
    Mar 19, 2012 8:12 AM   in reply to adamkay123

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points