Newbie has some questions


Results 1 to 40 of 44

Threaded View

  1. #30
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Now I want to tackle the bitwise AND & syntax.

    I think I am clear now on how we've come up with our 16 bit WORD seeds and what not.

    For this example it is W0=%0000000011101101

    When something like this is done:

    <b>randomlight=W0 & $000F</b>

    it is also like saying:

    <b>randomlight=W0 & %1111</b> correct?

    It is comparing the first four bits of the word so it looks like this:

    <b>%0000000011101101</b> - original word
    <b>%0000000000001111</b> - AND compare on bitlevel (narrow it down to 16 or less)
    <b>%0000000000001101</b> - result of the compare

    No matter how you compare with the second set of bits the results is the first four bits of the first set. The "&000F" is just a handy way of stripping away the bits that aren't needed?

    My result comes back as a decimal 13 in this case.

    But if I do it wanting to pick from 15 lights instead:

    <b>%0000000011101101</b> - original word
    <b>%0000000000001110</b> - AND compare on bitlevel (narrow it down to 15 or less)
    <b>%0000000000001100</b> - result of the compare

    Decimal 12

    If I wanted to I could compare any number of bits by adjusting the second row of numbers so I could use & %00FF to come up with:

    <b>%0000000011101101</b> - original word
    <b>%0000000011111111</b> - AND compare on bitlevel (narrow it down to 255 or less)
    <b>%0000000011101101</b> - result of the compare

    Decimal 237

    <b>%0001011011101001</b> - original word
    <b>%0000000011111110</b> - AND compare on bitlevel (narrow it down to 254 or less)
    <b>%0000000011101000</b> - result of the compare

    Decimal 232

    The only problem here is that I don't see where the results are <em>seldom</em> different in the final row than what the original first few bits in all the examples I also did on paper unless the second row has lots of zeros compared to the first row so I think I am missing a key point?

    It is getting a little confusing now understanding the exact function of bitwise AND. Can someone expand to fill in the gaps here?

    Am I, at least, close on this operation?

    Thanks.

    Bart
    Last edited by bartman; - 9th November 2004 at 05:21.

Similar Threads

  1. Olympic Timer
    By Melanie in forum Code Examples
    Replies: 47
    Last Post: - 17th September 2008, 19:46
  2. Analog port newbie questions
    By rngd in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 10th March 2008, 11:38
  3. Newbie: Temperature measurements
    By Budda in forum General
    Replies: 10
    Last Post: - 30th March 2007, 09:56
  4. Hi Everyone! Some newbie questions :-)
    By guest_05 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 28th October 2006, 22:24
  5. NEWBIE: Some basic questions using interrupts
    By JackPollack in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 8th March 2006, 02:59

Members who have read this thread : 2

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