Wednesday, 1 February 2012

Programming tricks


  1. Swap the contents of two registers.
    XOR R0, R1
    XOR R1, R0
    XOR R0, R1

    Remember "1" in result means differences, while "0" means same. However when the number apears in operation of XOR"1" means reverse and "0" means keep.
  2. To judge if two numbers are equal, we can also use XOR.
    XOR R0, R1
    If the result is 0, then R0 and R1 are equal. Otherwise they are not.
  3. Struct type allows the specification of elements of a structure into a fixed number of bits.
    struct fivebits
    {
        unsigned int flag : 1; 
    // act as switch, on (1) or off (0)
        signed int num   : 4; // number ranges from -8...7
                                : 3; // empty 3 bits used to align to 8bits, this is necessary for manipulation
    }

No comments:

Post a Comment

Difference between "docker stop" and "docker kill"

 To stop a running container, you can use either "docker stop" or "docker kill" command to do so. Although it seems doin...