OG Xbox Forums => Software Forums => Development => Topic started by: Yuyu on September 30, 2004, 11:44:00 PM
Title: C++ Help - No Functions Allowed
Post by: Yuyu on September 30, 2004, 11:44:00 PM
I'm having a hell of a time figuring out how to convert a decimal number inputted, to a binary number, and then to a hex number, without the use of the C++ functions that do it for you.
It is a .NET console application. Can anyone point me in the right direction of what I need to do. I know how to do these conversions manually on my own (on paper), I just do not know how to tell C++ to do them manually without the use of the functions for conversion.
This project is for a grade, so hopefully you can help without telling me exactly what my code should look like? Thanks to anyone who can help.
Title: C++ Help - No Functions Allowed
Post by: dankydoo on October 01, 2004, 10:31:00 AM
You are going to use bitmasking.
For decimal -> binary you should use a mask of 0x00000001 then bitshift to the left every character...i.e....
void printBinary(int num) { int bNum = 0;
for(int i = 0; i < 8; i++) { bNum = num & mask; mask = mask << 1; if(bNum) printf("1"); else printf("0"); }
} // etc....or something along those lines..
void printHex(int num) { int mask = 0xF0000000; int hNum= 0; for(int i = 0; i < 8; i++) { hNum = num & mask; mask >> 4; if(hNum < 10) printf('0' + hNum); else printf('A' + (hNum - 10));
}
this is the basic jist, give it a whirl, and try to figure stuff out on your own if it is for a grade, you won't learn if people just hand it to you....
dankydoo
This post has been edited by dankydoo on Oct 1 2004, 05:32 PM
Title: C++ Help - No Functions Allowed
Post by: Yuyu on October 01, 2004, 05:25:00 PM
Thanks. Thats what I needed. ;)
Title: C++ Help - No Functions Allowed
Post by: WBAGAM on October 01, 2004, 06:53:00 PM
dont know if this helps but the windows calculater has a binary to watever converter or watever u want to convert under the scintificsetting on the menu bar
Title: C++ Help - No Functions Allowed
Post by: Yuyu on October 03, 2004, 08:12:00 PM
QUOTE (WBAGAM @ Oct 1 2004, 06:53 PM)
dont know if this helps but the windows calculater has a binary to watever converter or watever u want to convert under the scintificsetting on the menu bar
Thanks, but I know how to do the converting in my head, sometimes I have top use pencil and paper.. I was just wondering where to get started for doing it manually in the C++ syntax.