I'm currently taking a Computer Science class at my school, and it started off easy enough. We were taught Binary, Hexadecimal and how to convert it, and now the teacher decided to go balls-to-the-wall hard on us and told us we had to make a program that converts Hex to Binary by reverse engineering his code, this is almost impossible for me since I have no idea what is going on and he won't give us his code so we can look at it by ourselves. So do any of you guys have any easy tutorial or guide? I can't find any out there, and the ones that are given assume you already know some things about programming already.
Thanks in advance.
What exactly has he given you? You say he wants you to reverse his code. But then say he wont give you his code.
[QUOTE=mcd1992;42631206]What exactly has he given you? You say he wants you to reverse his code. But then say he wont give you his code.[/QUOTE]
He puts the code on the projector so we can see it from our computers, but he won't give us the actual file. He said that we'd copy it if he gave the file to us, but that defeats the purpose of what we're trying to do.
[QUOTE=Ghost_Nixon;42631235]He puts the code on the projector so we can see it from our computers, but he won't give us the actual file. He said that we'd copy it if he gave the file to us, but that defeats the purpose of what we're trying to do.[/QUOTE]
You have to 'reverse engineer his code' but he doesn't want to 'give you the actual file' to 'reverse engineer' so he shows it on the projector or else you would 'copy it'.
That doesn't make any sense.
I think you've mixed up "reverse engineering" and "reading code".
[URL="http://www.cplusplus.com/doc/tutorial/"]http://www.cplusplus.com/doc/tutorial/[/URL] is decent enough.
I think he is looking for C tutorials though, not C++.
[QUOTE=Dienes;42635406]I think he is looking for C tutorials though, not C++.[/QUOTE]
If you know C++, you know C.
[QUOTE=supersnail11;42635617]If you know C++, you know C.[/QUOTE]
not quite, you may know the syntax, but there are huuuge differences in how the language actually works and what's available to you.
Right, and even the syntax has differences, e.g. having to repeat "enum" and "struct" when declaring a variable of such type. You just don't know this when you learn C++ only.
A lecturer at uni once told us that we should compile with g++ to get advanced C features.
[i]shudders[/i]
you could do it in a few lines with sscanf and sprintf
I goofed bad guys, he's actually teaching Java but said it was C. (but the tutorial for C++ will help later on) Thanks for the help though!
[QUOTE=supersnail11;42635617]If you know C++, you know C.[/QUOTE]
AFAIK, it's most likely the other way around.
Fuck. I was taught converting from Hex to Binary and Backwards not even a month ago, but can't remember the formula. I'll see what I can get in C++
I would say for loop going down or up and if's for A through F. At least in C++
[QUOTE=WhitePilot;42667167]Fuck. I was taught converting from Hex to Binary and Backwards not even a month ago, but can't remember the formula. I'll see what I can get in C++
I would say for loop going down or up and if's for A through F. At least in C++[/QUOTE]
If you wanted to get complex, here's how I converted from arbitrary bases in C#:
[csharp]
private static string base75 = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_.,!=-*(){}[]";
public static string ConvertBase(string value, int srcBase, int dstBase)
{
string sourceAlphabet = base75.Substring(0, srcBase);
string destAlphabet = base75.Substring(0, dstBase);
string wet = value;
BigInteger val = 0;
BigInteger mlt = 1;
while (wet.Length > 0)
{
char digit = wet[wet.Length - 1];
val += mlt * sourceAlphabet.IndexOf(digit);
wet = wet.Substring(0, wet.Length - 1);
mlt *= srcBase;
}
string ret = "";
while (val >= dstBase)
{
int digitVal = (int)(val % (BigInteger)dstBase);
var digit = destAlphabet[digitVal];
ret = digit + ret;
val /= (BigInteger)dstBase;
}
char digitc = destAlphabet[(int)val];
ret = digitc + ret;
return ret;
}
[/csharp]
You'd use it like ConvertBase("FF", 16, 2) for hex to binary, and ConvertBase("11111111", 2, 16) for binary to hex. It's probably more complex than you want to go, and you'd have to convert it to C++, but it might help someone else.
Sorry, you need to Log In to post a reply to this thread.