+ Reply to Thread
Results 1 to 4 of 4

Binary numbers

  1. #1
    Registered User
    Join Date
    06-11-2007
    Location
    abbotsford
    Posts
    2

    Lightbulb Binary numbers

    I use an excel spreadsheet to talk to my PLC using a data serever... my plc will only allow 4 digit decimal numbers because they are converted to BCD (4 numbers = 16 bits the plc max)... I can change the PLC to use Binary instead of BCD so I can count numbers past 9999... so my question is can I pull a number off my data server to a cell in excel and then convert that 1 cell from binary to decimal... I have linked the binary cell to the memory location on the plc... and it gives me back a number like 3420 instead of binary 0010111000100000 which is equivelent to Decimal 11808... the function I use to talk to the PLC is =DSData|Times!'v21022:b'... with v21022 being the memory location on my plc... and b being a dataserver function...

    Thanks in advance

    just for fun I converted 3420 from octal to decimal and it gave me 1808 coincidence?

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259
    Hello Mithrandir,

    Here is the code to convert a decimal number into a binary text string. This formats the binary in groups of 4 bits with the MSB at the left (Big Endin format).

    Please Login or Register  to view this content.
    Example:
    Please Login or Register  to view this content.
    B will be formatted like this... 10 1110 0010 0000

    Sincerely,
    Leith Ross

  3. #3
    Valued Forum Contributor Richard Schollar's Avatar
    Join Date
    05-23-2006
    Location
    Hampshire UK
    MS-Off Ver
    Excel 2002
    Posts
    1,264
    Quote Originally Posted by mithrandir
    ... so my question is can I pull a number off my data server to a cell in excel and then convert that 1 cell from binary to decimal...
    Here's some code I wrote a while ago which converts binary string values to decimal:

    Please Login or Register  to view this content.
    This code does have a few limitations: only takes strings; assumes all binary strings are positive (ie does not allow for twos complement numbering); no fractional numbers (hopefully this won't cause you issues).

    Hope this helps!

    Richard

  4. #4
    Registered User
    Join Date
    06-11-2007
    Location
    abbotsford
    Posts
    2

    Red face

    Thanks for all the help...

    I am horrible at explaining myself... I need to bring the number to excel in binary format then convert that binary number to decimal... the problem is... instead of showing up as binary in excel it shows up as octal and is missing a digit... although I do need to later convert that binary value to a decimal... the number will only get bigger so I am not worried about complements...

    Thanks again
    Last edited by mithrandir; 06-12-2007 at 10:39 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1