Need help to understand what this function is doing

This is a discussion on Need help to understand what this function is doing within the C Programming forums, part of the General Programming Boards category; Hello! I'm new here and new at C. I am working off some example code and modifying it to suit ...

  1. #1
    N_N
    N_N is offline
    Registered User
    Join Date
    Feb 2011
    Posts
    3

    Need help to understand what this function is doing

    Hello!
    I'm new here and new at C. I am working off some example code and modifying it to suit my application.
    I don't understand the example code even though I think it is basic.
    I'll start with a function referenced.
    I do not understand what |= means (line 5 of function)

    Code:
    void WriteByte (uchar DATA)
    {
       uchar RG = 0;
       unit temp = 0xB800;
       temp|=DATA;
         if (RG = 0)
        {
        goto loop;
         }
         else
        {
         RG = 0;
          }
    }
    
    void main()
    uint ChkSum;
    while (1)
    {
           ChkSum = 0;
           WriteByte (0x30);
           ChkSum+=0x30;
           WriteByte (0x31);
           ChkSum+=0x31;
    
           WriteByte (0x32);
           ChkSum+=0x32;
           WriteByte (0x33);
           ChkSum+=0x33;        // what does += mean?
    
           ChkSum&=0xFF;        // what does &= mean?
           WriteByte(ChkSum);
    }
    Any help is appreciated.
    N_N

  2. #2
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    It is a bitwise OR to set a bit I believe.
    so if it is
    i=0;
    i = 0|1
    i becomes 1
    You ended that sentence with a preposition...Bastard!

  3. #3
    N_N
    N_N is offline
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    Thank you!
    What about the rest? What does += mean and &=?
    And what is the code doing?
    Thanks!
    N_N

  4. #4
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    += ??
    is the same as

    n = n+1

    &= bit wise..clears a bit

    n=1
    n = 1&0
    n is now 0

    for example

    A is 65 0100 0001
    to get that to be
    i will clear bit 0 and set bit 2

    char a = A
    a&=0x01 ;
    a|=0x02 ;

    a is now B.
    that should work..if it didn't well it is something like that..
    and if it did, it should make things clearer..
    and know I have no freaking idea what that code does...
    you copied and paste from some random site huh?
    You ended that sentence with a preposition...Bastard!

  5. #5
    N_N
    N_N is offline
    Registered User
    Join Date
    Feb 2011
    Posts
    3
    Thanks-
    Well no, it is not from some random site exactly
    I am configuring a RFM12 transceiver to work with a PIC.
    http://www.hoperf.com/upfile/RF12_code.pdf

    There is some FSK protocol that I have no freakin idea about and how to transmit data wirelessly. That is what the code is doing- transmitting wireless data by accessing internal registers on the RFM12 chip.

    So what I have copied and pasted is a little bit edited (I took out all the stuff that has nothing to do with transmitting). Also- it is from a different site than the pdf I posted, I found some sample code with comments.

    It is hard for me to dissect sample code because I haven't done much C coding in the past few years.
    N_N

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 03:25 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  3. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21