Thread: variable into 1 bit??

  1. #1
    Registered User
    Join Date
    Oct 2006
    Posts
    5

    variable into 1 bit??

    if I have a 16 bit variable (number) and I try to send it out one bit at a time on RCO (the first bit of a register also the data line) will it work as I intend it??

    example: *Note RC0 is first bit of register...

    //code

    RC0=number;
    RCO=number >>1;
    RCO=number>>2;
    RCO=number>>3;
    etc ...
    etc....

    //end code

    if not... any other simple suggestions??

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Hard to tell if that would work.
    If RC0 is supposed to be only one bit then it might be better to use
    Code:
    RC0 = number & 1;
    RC0 = ( number >> 1 )& 1;
    Anyway, using a loop would improve the solution.
    Kurt

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Quote Originally Posted by theeld
    if not... any other simple suggestions??
    What device? Do you have to bit-bang it or are there available peripherals?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    C can't just read one bit. So if your program is written in C, (whatever's reading on the other end) the smallest you're sending across is going to be one byte, or rather, a char (CHAR_BIT in size). Likewise, the smallest you can send is going to be one byte also.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. spliting 16bit variable into LSB and MSB 8 bit variables
    By Spiral Prophet in forum C Programming
    Replies: 2
    Last Post: 10-30-2008, 02:28 PM
  3. Replies: 7
    Last Post: 12-10-2004, 08:18 AM
  4. bit patterns of negtive numbers?
    By chunlee in forum C Programming
    Replies: 4
    Last Post: 11-08-2004, 08:20 AM
  5. Copy bit to bit
    By Coder2Die4 in forum C Programming
    Replies: 15
    Last Post: 06-26-2003, 09:58 AM