|
|
bit shifting
Hello
I'm working on the code for the embedded platform, where I need to obtain a
value for on of 32 GPIO pins. On this platform sizeof(unsigned int) is 32,
so I've come up with such macro:
#define GPIO(x) (0x1u << (x))
Is this fine or has any disadvantages!
--
Mark
|
|
0
|
|
|
|
Reply
|
Mark
|
12/30/2009 8:25:24 AM |
|
"Mark" <mark_cruzNOTFORSPAM@hotmail.com> writes:
> I'm working on the code for the embedded platform, where I need to
> obtain a value for on of 32 GPIO pins. On this platform
> sizeof(unsigned int) is 32,
I think you mean sizeof(unsigned int) is 4. By the way, a lot of
people quote sizes when the quantity that matters is really the
maximum for that type. On some C implementations, sizeof(int) can be
1 yet MAX_INT can be a respectable 2147483647. The simplest thing
would be for you to say that, on your machine, unsigned int has 32
value bits.
> so I've come up with such macro:
>
> #define GPIO(x) (0x1u << (x))
>
> Is this fine or has any disadvantages!
I think it is fine. I'd write 1u rather than a hex constant but that
is just my taste. All macros have some disadvantages, but you use all
caps so the reader will know that GPIO is not a function.
--
Ben.
|
|
0
|
|
|
|
Reply
|
Ben
|
12/30/2009 11:44:39 AM
|
|
|
1 Replies
329 Views
(page loaded in 0.04 seconds)
Similiar Articles: bit shifting - comp.lang.c"Mark" <mark_cruzNOTFORSPAM@hotmail.com> writes: > I'm working on the code for the embedded platform, where I need to > obtain a value for on of 32 GPIO pins. Bit-Shifting in ASM - comp.lang.asm.x86Hello, I was wondering if there is a command in assembly that can shift the bits of a given binary string to the left. For example, the string 11100... Signed shift of 32-bit int using 16-bit instructions? - comp.lang ...I'm working on a hobby project in 16-bit DOS and trying to figure out how to do a signed shift left of a 32-bit signed integer in DX:AX. I have alrea... Bitwise Rotate Left / Right? - comp.lang.asm.x86Signed shift of 32-bit int using 16-bit instructions? - comp.lang ..... trying to figure out how to do a signed shift left ... signed shr, bit into carry rcr ax,1 ... need a help in vhdl code developing - comp.lang.vhdlhi everyone, I am trying to develop a vhdl code for 8 bit shift register with input as parallel input and serial output.can anyone help me with the... sse2 and rolr - comp.lang.asm.x86Working with 32-bit shifts only could be handled with two initial 4x32 shuffle operations, that gets the high and the low part of each result word into the right ... About instruction lea - comp.lang.asm.x86Bit-Shifting in ASM - comp.lang.asm.x86 About instruction lea - comp.lang.asm.x86 bit shifting - comp.lang.c About instruction lea - comp.lang.asm.x86... ebx // ebx = ecx ... SystemVerilog: how to achieve VHDL like unconstrained type ...Queues support shifting rather neatly: Q =3D {Q[1:$], new_bit}; However, some tools don't support the {} queue-concat syntax and you may need to do bit Q ... Suitable Integer Square Root Algorithm for 32-64-Bit Integers on ...The reason is that NR iteration in this case does not involve any division except for a bit shift: x' = x - g(x)/g'(x) = x - (1/x^2 - y) / (-2 / x^3) = x ... Bitwise operation - Wikipedia, the free encyclopediaA bitwise operation operates on one or more bit patterns or binary numerals at the level of their individual bits. It is a fast, primitive action directly supported ... operators - Absolute Beginner's Guide to Bit Shifting? - Stack ...I've been attempting to learn C in my spare time, and other languages (C#, Java, etc.) have the same concept (and often the same operators) ... What I'm wondering is ... 7/23/2012 7:34:06 PM
|
|
|
|
|
|
|
|
|