As part of my homework for discrete math I need to convert different decimal values, both positive and negative, to 8-bit binary representations using signed magnitude, 1's complement, and 2's complement. Could anyone suggest an elegant way to present my solutions?

I'm not sure it's a TeX question; broading your question might help to know what you are really after.
–
c.p.Feb 2 '13 at 0:07

1

Welcome to TeX.sx! Do you need another visual example of how to present this kind of algorithm or do you actually want to know how to achieve the linked example in (La)TeX? The former is off-topic, for the latter you might specify where you got stuck reproducing the example: The arrows? The matrix-ish presentation? The lines around the decimal numbers? …?
–
QrrbrbirlbelFeb 2 '13 at 0:09

3 Answers
3

In your initial question I thought you were looking at suggestions for ways of tabulating the bit patterns, something like the first couple of examples. But your edit indicated you wanted to display the working. Something like this might work for that, I just do the easy unsigned case as you showed, I leave the rest as you say it's homework:-)

Update: I add at the end an illustration of the reverse process of base b to decimal conversion

I have not tried to do the upgoing arrow... I am sorry for all those @ which render the code barely readable (to me). I originally used \n, \m etc... but one always fears overwriting something in LaTeX.

The method uses an expandable loop inside a tabular, so as to get alignment on the right. No test is done on the input which should not be negative.

I do a little play with local and global assignments but maybe using one more count variable would give a more easily readable code. The point anyhow is that computations should not be done twice, despite the restricted scope due to the tabular cell.

When the base is $\leq 36$, the digits use the alphabet starting with $10 = A$.

Yes, if all you need is to print a 0; you're losing full expandability, of course.
–
egregFeb 3 '13 at 12:12

@egreg @JosephWright Some person or software keeps on modifying my code. I read now \newcommand{\baseexpansion}[2][1] where my original file from which I copy-pasted had \newcommand{\baseexpansion}[2][2] and I never never wrote [2][1]. And similarly I already manually reverted \newcommand{\todecimal}[2][4] to my original \newcommand{\todecimal}[2][2]. I don't know what's going on here. Perhaps the [2][1] was there when I already reverted the [2][4].
–
jfbuFeb 3 '13 at 14:00