Is Number Odd?


Results 1 to 30 of 30

Thread: Is Number Odd?

Threaded View

  1. #16
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by sayzer View Post
    Ski, is this ridiculous enough? I can go deeper.
    Keep going!!!

    (What do they call those 'machines' that take the most indirect route to accomplish something? Remember that kids game 'Mousetrap'?)

    My next submission:
    Code:
    testnumber var word
    onescount var byte
    onescount1 var byte
    loopvar var byte
    
    testnumber = 12345
    
    main:
    for loopvar = 0 to 15 'counts bits set in the testnumber
    if testnumber.0[loopvar] = 1 then
    onescount = onescount + 1
    endif
    next loopvar
    
    testnumber = testnumber >> 1 'shifts the LSB out
    testnumber = testnumber << 1 'shifts a zero bit back in
    
    for loopvar = 0 to 15 'recounts bits set in the testnumber
    if testnumber.0[loopvar] = 1 then
    onescount1 = onescount1 + 1
    endif
    next loopvar
    
    if onescount = onescount1 then lcdout "EVEN" 'if the number of set bits is the same, its even
    if onescount <> onescount1 then lcdout "ODD"
    STOP 'please stop!
    Last edited by skimask; - 11th June 2008 at 16:34.

Similar Threads

  1. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  2. dec number to show on lcd (maths)
    By savnik in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2007, 19:18
  3. Working with the random number generator
    By kwelna in forum mel PIC BASIC
    Replies: 9
    Last Post: - 16th January 2007, 17:50
  4. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 17:39
  5. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 17:55

Members who have read this thread : 0

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