A Bit manipulation brain teaser for you :)


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    Cool!..... Yes,
    Then I could write a book and title it "Picing up the PC"

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    But how do do it in a PIC where your greatest mathmatic result is limited to <= 65535?
    Well, you place those limitation yourself. You could still use 2 Words... some basic maths around that. But will this worth if you could do most of the job on your PC side? It's up to you.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default

    Hi,
    I don't want to pretend I know the answer but may have an idea....
    What do you intend to with the value once (if) you have it?

    /Henrik Olsson.

  4. #4
    Join Date
    Jul 2003
    Posts
    2,358


    Did you find this post helpful? Yes | No

    Default

    I have 4 (8 bit) bytes being sent to me in a serial string.

    Byte_1 is to be multiplied by 16777216
    Byte_2 is to be multiplied by 65536
    Byte_3 is to be multiplied by 256
    Byte_4 is to be multiplied by 1
    Not exactly a Brain Teaser - more a trick question.

    Byte_1 is the MSB of a 32-bit variable, Byte_4 is the LSB of your 32-bit variable... no maths needed... so what you're really asking for is a routine to output a 32-bit (four byte) variable in human readable decimal...

  5. #5
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    Hi Melanie,
    I thought I posted this the other day, but perhaps the system kicked me out for not posting fast enough.

    The 4 bytes represent a value from 0 - 30,000.000
    So fortunatly for me, the highest Byte will only be a 1 or 0.
    The numbers represent radio frequency.
    I have a radio that is sending me the 4 bytes to indicate what its current frequency is.
    I have a number of frequency windows to play in.
    I split each one of these windows up into 8 slices.
    The frequency value then gets matched to one of these slices.
    I use this info to control a remote antenna tuner box I made last winter.
    I would bet you call this one simple.
    But its over my head
    Thanks
    Duane

  6. #6
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by dw_picbasic View Post
    ...
    The 4 bytes represent a value from 0 - 30,000.000
    Can you split 30,000 from .000?

    If you can, then you can put 30,000 into a word variable, and the remaining three zeros (.000) can get into another word variable (in theory).

    If of course this is only for display purposes!


    -------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  7. #7
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    how the data is sent? Did you tried to attach your radio directly to a PC? Maybe he just send you ASCII string or HEX value?

    in fact it could make sense... let's assume it send you 4 Bytes...
    30,000.000
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  8. #8
    Join Date
    Jan 2007
    Posts
    78


    Did you find this post helpful? Yes | No

    Default

    Yes, the device is setup to talk to a PC.
    The PC queries the device for its set frequency, and the device returns the 4 bytes.

    I know I should push the 4 bytes into 2 seperate 16 bit words.
    Then I need to figure out what the decimal part is for:

    Millions
    Thousands
    Hundreds

    This seem pretty straight forward for a 1 byte word, but no so easy for me to get my head around doing it for 2 bytes, due to the carry effect.

Similar Threads

  1. Bits, Bytes Words and Arrays
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 24
    Last Post: - 14th June 2016, 07:55
  2. How to receive stream of bytes using PIC USART
    By unifoxz in forum mel PIC BASIC Pro
    Replies: 34
    Last Post: - 20th June 2009, 10:38
  3. Sleep Mode
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 13th March 2008, 10:31
  4. PICBasic newbie problem
    By ELCouz in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 12th February 2008, 00:55
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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