Writing a C Macro
Posted
by shaharg
on Stack Overflow
See other posts from Stack Overflow
or by shaharg
Published on 2010-04-15T10:13:05Z
Indexed on
2010/04/15
11:13 UTC
Read the original article
Hit count: 270
Hi, I have to write a macro that get as parameter some variable, and for each two sequential bits with "1" value replace it with 0 bit. For example: 10110100 will become 10000100. And, 11110000->00000000 11100000->100000000
I'm having a troubles writing that macro. I've tried to write a macro that get wach bit and replace it if the next bit is the same (and they both 1), but it works only for 8 bits and it's very not friendly...
P.S. I need a macro because I'm learning C and this is an exercise i found and i couldn't solve it myself. i know i can use function to make it easily... but i want to know how to do it with macros.
Thanks!
© Stack Overflow or respective owner