This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Simple question on 10*0x1000u

I can not find a reference or definition for 10*0x1000u  in a whole stack of c books or an hour on-line
In context I know it is 0010b So 0x1000 represents 0000b  and 10* is increment 10 in effect
I get the u = unsigned int part

So;
What is it?
Is it common, or unique to the MSP430 library?
What is it called?

Thank you...

-H

  • H,

    Sounds like you opened an MSP430 device header file to find this definition.

    Did it look anything like this?

    (1) #define

    ADC12SHT1_10 (10*0x1000u) /* ADC12 Sample Hold 1 Select Bit: 10 */

     An explanation for this example:

    The bit location of ADC12SHT1 in that specific register is given by:

     (2) ADC12SHT10 (0x1000) /* ADC12 Sample Hold 1 Select Bit: 0 */(2) #define

    Line 1 is used to fill in the bit pattern corresponding to decimal 10 or 1010b at the bit location 0x1000 i.e. ADC12SHT10.

    I would recommend using the actual definitions such as ADC12SHT1_10 instead of using numerical expressions; as these make the code difficult to read or debug.

    Regards,

    Priya

  • Hello,

    I understand the multitude of approaches for using bit masking and constants to set registers. What I do not understand in the syntax and basis for (10*0x1000u) as a method of generating a bit mask or hex value.

    I cannot find it in Prata's book, the ANSI c spec, the IAR help files or surfing the net. The use of the * suggests multiplication, pointers, array handling and other things, but not increment.

    I'm guessing this is a special function or macro uniquely in the MSP430 library.

    Can someone tell me a bit about YY*0xZZZZ

    Thanks

    -H

     

  • YY is a number in decimal representation. (Each Y must be a decimal digit.)

    0xZZZZ is a umber in hexadecimal representation. (Each Z must be a hexadecimal digit.)

    The * between them means multiply.

    (You omitted the U suffix, which means unsigned.)

  • Thank you old yellow cow. This is what I was looking for.

    I wonder where the prototype is.

    -H

  • H Stewart said:
    I understand the multitude of approaches for using bit masking and constants to set registers. What I do not understand in the syntax and basis for (10*0x1000u) as a method of generating a bit mask or hex value.

    It is indeed an uncommon way to do it, yet it is simple math.

    0x1000u just defines the lowest bit of the masked area. The multiplication with any value results in this value being shifted to the masked area. It is the very same as the more common notation (10<<12), which also shifts 10 by 12 bit (or multiplies it with 0x1000). Both notations are parsed to the identical code.

    Personally, i prefer the use of <<, as it makes it obvious that it is a shift operation. The multiplication with 0x1000 leaves the possibility that there could be a multiplication with 0x1001 too (which wouldn't be a shift anymore).

    H Stewart said:
    Can someone tell me a bit about YY*0xZZZZ

    In this multiplication value, only 1 bit may be set, all other bits must be 0 or it won't make sense. So it isn't ZZZZ at all. It is rather yy*0xABCD where exactly one of A,B,C,D is 1,2,4 or 8, and all others must be 0. Using '<<' is much more obvious. And since all TI datasheets count the bit numbers in the register value descriptions, it also fits the docs better.

    On the bottom line, it makes absolutely no difference whether you  use x<<y or x*z for a shift. As long as x and y/z are constants, both expressions resolve a constant value at compile-time and do not cost any processor power at all.

**Attention** This is a public forum