Is it possible to implement bitwise operators using integer arithmetic?

后端 未结 6 1431
青春惊慌失措
青春惊慌失措 2021-01-29 22:05

I am facing a rather peculiar problem. I am working on a compiler for an architecture that doesn\'t support bitwise operations. However, it handles signed 16-bit integer arithme

6条回答
  •  野性不改
    2021-01-29 22:21

    In this environment it might be best if you could set up to actually use arithmatic operators to peel out components of integers.

    E.G.

    if (a & 16)  becomes if ((a % 32) > 15)
    a &= 16 becomes if ((a % 32) < 15) a += 16
    

    The transforms for these operators are obvious enough if you restrict RHS to a constant power of 2.

    Peeling off two or four bits is also easy to do.

提交回复
热议问题