Decimal to Binary Conversion


Closed Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2006
    Location
    Brooklyn,NY
    Posts
    32

    Smile Decimal to Binary Conversion

    I recently found a short simple algorithm to convert decimal to binary. Alas, it requires raising a number to a power. In Basic Basic, this notation was n^p. I have checked the math operators over and over in PBP and could not find this operator. The ^ is a bitwise exclusive or.

    I require a simple program to convert a 1 to 3 digit decimal number to an eight bit binary number.

  2. #2
    Join Date
    Aug 2006
    Location
    Look, behind you.
    Posts
    2,818


    Did you find this post helpful? Yes | No

    Default For your purpose . . .

    Hi schlaray,
    Are you asking how to display a number in a different format?
    You can store a number in a variable and display it as you want using the BIN, DEC, or HEX modifiers - see page 143 PB PRO manual and it will display in whichever format you choose. Hope this helps. JS

  3. #3
    Join Date
    Feb 2003
    Location
    Salt Lake City, Utah USA
    Posts
    517


    Did you find this post helpful? Yes | No

    Smile

    It's not clear what you are trying to do. Study what Joe has proposed. In case you really want to do this ....

    Code:
    ' n^p (n to the power of P)
    ' n = 2
    ' p = 5
    ' x = 2^5 = 32
    ' in PBP
    x var byte
    p var byte
    p = 5
    x = 1
    x = x << p	' x = 32
    
    ' or 
    ' n = 10
    ' p = 3
    ' x = 10 ^ 3 = 1000
    ' in PBP
    x var word
    y var byte
    p var byte
    x = 1
    for y = 1 to p
    x = x * 10
    next y	
    ' x = 1000
    Paul Borgmeier
    Salt Lake City, UT
    USA
    __________________

  4. #4
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,614


    Did you find this post helpful? Yes | No

    Wink Manual, Where are you, my sweet manual ????

    Quote Originally Posted by schlaray View Post
    I require a simple program to convert a 1 to 3 digit decimal number to an eight bit binary number.
    Hi,

    First: note 8 bits binary number has a 255 ( decimal ) limit ... not 999 !!!

    Second : your pics only works ( internally ...) with binary ...

    Soooo, you already have what you're looking for !!!
    as Joe says, it's just a displaying question ...

    Read Manual page 93+ for further info.

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  5. #5
    Join Date
    Nov 2006
    Location
    Brooklyn,NY
    Posts
    32


    Did you find this post helpful? Yes | No

    Default Decimal to Binary conversion

    Pages 93 and 143 explains it all. Thank you all. Thats the way we speak in South Brooklyn.
    Schlaray.

Similar Threads

  1. Binary Coded Decimal
    By -Dan- in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 25th May 2009, 09:23
  2. Help for decimal conversion
    By eva in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 15th March 2007, 18:20
  3. microns to decimal conversion
    By Rleonard in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 28th February 2007, 14:37
  4. Binary to Decimal from ADC
    By RYTECH in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 27th July 2005, 18:51
  5. Decimal to binary conversion
    By Demon in forum Code Examples
    Replies: 9
    Last Post: - 25th February 2005, 20:05

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts