1. #### assembler level question

I am trying to convert a hex number into a binary one, and im having some trouble. for output, i am getting odd symbols, like smiley faces or triangles etc.. here's my code, any help greatly appreciated:

//Ex03s07_BinOut32
#include <iostream.h>
#include <conio.h> // for putch()

void HexOut32(int m)
{
// outputs m binary.
char c; // tmp variable
__asm
{
mov eax, m
push ebx ; save reg so can use
push ecx
mov ch, 32 ; 32 binary digits to display
HexOut32_1:
mov CL, 1
rol eax, CL
mov BL, AL
; determine binary code for digit

HexOut32_2:
mov c, BL
push eax ; save value
push ecx ; save count
}
_putch (c);
__asm
{
pop ecx ; restore counts
pop eax ; restore value
dec ch
jnz HexOut32_1
pop ecx
pop ebx
}
return;
}

int main()
{
int n;
do
{
cout << "\n\nEnter number (in hex, 0 to exit): ";
cin >> hex >> n;
if (n == 0) break;
cout << "Here it is: "; cout.flush();
HexOut32(n);
} while (1);
return 0;
};
2. Try changing this part:
; determine binary code for digit

to this:
; determine binary code for digit

Hope this helps!
3. U ROCK MAN!!! THANKS!! tried it and it works, but one question:

i'm one of those types who has to know why everything works...
4. No Profile Picture
Contributing User
Devshed God 1st Plane (5500 - 5999 posts)

Join Date
Oct 2000
Location
Back in the real world.
Posts
5,966
Rep Power
191
you need to add 0x30 = 48. :)
5. oh god i just figured out what it was, i was looking at the ascii set with hex indices!! LOL, in hex 0 = 30 and 1 = 31!! thanks a lot for your help guys!! much faster than my jerk teacher who hasnt replied to my email in 2 days.:rolleyes: