I am translating a C++ program into pseudo-code using the algorithmicx package.
Do you know how I can represent the C bitwise operator like the shifts (<< and >>) ?
Until now I used power of 2 but it's not very convenient.
|
I am translating a C++ program into pseudo-code using the Do you know how I can represent the C bitwise operator like the shifts (<< and >>) ? Until now I used power of 2 but it's not very convenient. |
||||
|
Pseudocode has a different purpose compared to the actual programs. It should convey ideas, not implementation, and as such should be as close to the natural language as possible. Therefore I think it's not good to introduce programming language-specific syntax in the algorithm listing. I suggest one of these options:
|
|||
|
|
|
I advise against Andrey’s solution. He is right that in general pseudocode should be independent of a specific machine or language. But this breaks down with bit operations. Bit operations do suggest a specific underlying architecture, and the bit operators follow an established nomenclature. You don’t make the code more readable by ignoring this convention – in fact, you do the opposite. I have the following commands defined in my thesis template:
(The command names follow the naming convention of the That said, you should second-guess your reason for using bit operations in the first place – often they are only used to achieve specific optimisations, in which case they have no place in a pseudo-code. On the other hand, sometimes (and it sounds as if this may be the case for you) they have a legitimate purpose. |
|||
|
|
For symbols, you can use
You can also define some functions:
and use |
|||||||||||
|
|
Use the
and
if you need to have those operators displayed exactly as they would be typed in a program, and do not want to use other packages for that. |
|||
|
|
|
In mathematics My suggestion is to combine the answers of Konrad and PointedEars thusly:
The \verb command is overpowered for this purpose and has some restrictions which make it harder to work with. I use |
||||
|
|
x \cdot 2^nandx / 2^n, wherenis the shift amount. – Andrey Vihrov Mar 25 '11 at 11:08