|
You last visited: Today at 01:57
Advertisement
Help with pseudocode
Discussion on Help with pseudocode within the C/C++ forum part of the Coders Den category.
08/31/2012, 00:49
|
#1
|
elite*gold: 0
Join Date: Oct 2006
Posts: 45
Received Thanks: 14
|
Help with pseudocode
Can someone help me with writing a pseudocode for converting hex to decimal?
|
|
|
08/31/2012, 02:52
|
#2
|
elite*gold: 55
Join Date: Mar 2006
Posts: 4,582
Received Thanks: 1,537
|
maybe this?
Code:
int x;
std::cin >> std::hex >> x;
std::cout << x << std::endl;
return 0;
|
|
|
08/31/2012, 03:26
|
#3
|
elite*gold: 0
Join Date: Oct 2006
Posts: 45
Received Thanks: 14
|
Could you kindly explain what those things even mean? LOL. My class for programming just started and i dont know much
|
|
|
08/31/2012, 12:37
|
#4
|
elite*gold: 273
Join Date: Sep 2010
Posts: 1,831
Received Thanks: 786
|
Quote:
Originally Posted by EatMyChidori
Could you kindly explain what those things even mean? LOL. My class for programming just started and i dont know much
|
Code:
std::cin >> std::hex >> x;
Saves an hexadecimal value to x.
Code:
std::cout << x << std::endl;
or
Code:
std::cout << std::dec << x << std::endl;
Shows the value in the decimal system.
|
|
|
08/31/2012, 14:49
|
#5
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,904
Received Thanks: 25,394
|
That's no pseudo code.
|
|
|
09/01/2012, 22:29
|
#6
|
elite*gold: 0
Join Date: Aug 2012
Posts: 18
Received Thanks: 9
|
Here's some C-inspired "pseudocode"
Quote:
mul = 1;
for (i = hex.length; i>= 0; i--, mul*16)
{
result += hex[i] * mul;
}
|
I hope that's what you were looking for
|
|
|
09/01/2012, 23:52
|
#7
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,904
Received Thanks: 25,394
|
That wouldn't do the job, since hex characters may include letters (A-F) that cannot be multiplied with 16.
|
|
|
09/02/2012, 01:12
|
#8
|
elite*gold: 0
Join Date: Aug 2006
Posts: 276
Received Thanks: 117
|
Well, it's bad pseudo-code and only a "quick'n'dirty" solution, but maybe it helps... :-)
Quote:
long f(character *a, integer length)
{
integer i;
long value = 0;
for(i=0;i<length;i++)
if(a[i] <= 57) //look at ASCII Table, if you don't understand this :-)
value += (a[i]-48) * (1 leftshift (4*(length-1-i)));
else
value += (a[i]-55) * (1 leftshift (4*(length-1-i)));
return value;
}
|
|
|
|
09/02/2012, 02:00
|
#9
|
elite*gold: 0
Join Date: Aug 2011
Posts: 12
Received Thanks: 15
|
C++ solution was posted above, however this is the C solution:
Code:
int nInteger = 0;
scanf_s( "%x", &nInteger );
printf_s( "%i", nInteger );
|
|
|
09/02/2012, 03:29
|
#10
|
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,904
Received Thanks: 25,394
|
Quote:
Originally Posted by Jadd
C++ solution was posted above, however this is the C solution:
Code:
int nInteger = 0;
scanf_s( "%x", &nInteger );
printf_s( "%i", nInteger );
|
Well, I'm clearly sure, that he needs to write the algorithm himself instead of using libraries.
|
|
|
09/03/2012, 16:56
|
#11
|
elite*gold: 0
Join Date: Sep 2005
Posts: 426
Received Thanks: 87
|
Algo works from right to left.
Divide number by 16. Keep the quotient for next iteration, the remainder is the figure you are looking for. It will ovbviously be between 0 and 15, convert that to 0..F
As long as quotient is >= 16, repeat.
|
|
|
09/04/2012, 06:34
|
#12
|
elite*gold: 0
Join Date: Aug 2006
Posts: 276
Received Thanks: 117
|
Quote:
Originally Posted by kissein
Algo works from right to left.
Divide number by 16. Keep the quotient for next iteration, the remainder is the figure you are looking for. It will ovbviously be between 0 and 15, convert that to 0..F
As long as quotient is >= 16, repeat.
|
he want's to convert hex to decimal, not decimal to hex :-)
|
|
|
09/04/2012, 11:06
|
#13
|
elite*gold: 0
Join Date: Sep 2005
Posts: 426
Received Thanks: 87
|
Quote:
Originally Posted by Ensky
he want's to convert hex to decimal, not decimal to hex :-)
|
ups sorry, my fault.
-Get the last digit of the hex number, call this digit the currentDigit.
-Make a variable, let's call it power. Set the value to 0.
-Multiply the current digit with (16^power), store the result.
-Increment power by 1.
-Set the the currentDigit to the previous digit of the hex number.
-Repeat from step 3 until all digits have been multiplied.
-Sum the result of step 3 to get the answer number.
Example:
Convert the number 35432 HEXADECIMAL to DECIMAL
2x(16^0) + 3x(16^1) + 4x(16^2) + 5x(16^3) + 3x(16^4) =
2 + 3x16 + 4*256 + 5*4096 + 3*65536 =
2 + 48 + 1024 + 20480 + 196608 =
218162
|
|
|
|
Similar Threads
|
[GAME.ELF] Pseudocode %3 FULL decomple!! + IDA project
09/12/2011 - Metin2 PServer Guides & Strategies - 13 Replies
or turkish forum in quote;
but is really good decomp..
|
AutoIt WoW Bot "Pseudocode" Frage
06/22/2011 - AutoIt - 10 Replies
Hi Community :)
Ich hab mir in letzter Zeit ein bischen was zu MemoryReading angeschaut und denke / hoffe das ich in nächster Zeit auch mal was damit anstellen kann.
Mein erste Ziel wäre ein, wie gesagt, WoW Bot, der Anti-Afk wo rum steht, und nach Mobs IM SPEICHER sucht, und wenn er was gefunden hat, eine bestimmte Rotation macht, das der Mob auch stirbt.
So jetzt zur Frage wie man das angeht:
Wie suche ich Gegner im Speicher ?
Und wenn ich was gefunden habe einfach mit...
|
[RELEASE] Game File Pseudocode (Sourcecode)
08/07/2010 - Metin2 PServer Guides & Strategies - 51 Replies
Hello,
This time i want to release the C Pseudocode of the Game you can not compile it but its useful because you can read it easier than ASM and you see more Informations in the right format.
I attached the file in this thread.
I hope this can help you greetings lolkid2009
There is no Copyright secured stuff in this thread the Code is dynamically generated from the ASM and is only useable to gateher informations.
|
[RELEASE] Client Source (Pseudocode)
07/14/2010 - Metin2 PServer Guides & Strategies - 22 Replies
Hello,
Same as in my Old Thread with the Game Source here i give you the Client Source it's pure Pseudocode and like the Game Source not compile able.
The Function names aren't good because of my IDA settings.
But i think you can still use it.
It's attached in this Thread.
|
All times are GMT +2. The time now is 01:57.
|
|