Halp ! T.T

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Post Reply
Rebornxeno
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Thu Jun 23, 2011 11:12 am

Halp ! T.T

Post by Rebornxeno »

YO yo wadupp peepz REBORN IN DA HIZOUSE!

Okay here I have a problem, i've written a simple thing that converts numbering systems yeah? Well if I try to convert from binary to any other numbering system, it just stays binary (decimal system) or fux up. Works pretty well for any other numbering system though, and I feel as if the problem is in how I'm expressing the "binary" numbers given to the function. If someone can let me know how I can "express" the "binary" numbers I'll be much obliged.

Code: Select all

#include "stdafx.h"
#include "iostream"
#include "math.h"

int *convert(int number,int base)
{
	int power = 1;
	int count = 0;
	while (number > pow((double)base, power))
	{
		power++;
	}
	count = power;
	int *iArray = new int[count];
	int *lArray = new int[count];
	for (int k = 0; k < count; k++)
	{
		iArray[k] = number % base;
		number/= base;
	}
	for (int k = 0; k < count; k++)
	{
		lArray[k] = iArray[count-k-1];
		std::cout << lArray[k] << std::endl;
	}

	return lArray;
}
int _tmain(int argc, _TCHAR* argv[])
{
	convert(123456789,16);
	return 0;
}

In case it helps, I'm using this to change from decimal and hex numbers into binary, doing xors and what not on the binary numbers, and then return back to decimal/hex. The problem is the returning from binary to decimal/hex.
User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: Halp ! T.T

Post by dandymcgee »

Rebornxeno wrote:YO yo wadupp peepz REBORN IN DA HIZOUSE!
Certainly not your IQ.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
Rebornxeno
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Thu Jun 23, 2011 11:12 am

Re: Halp ! T.T

Post by Rebornxeno »

Certainly not your sense of humor.

Weird that google doesn't bring up a single thing about binary to decimal algos but tons of the opposite. Now that I've had time to ponder over it I think that the change won't be so difficult after all. I'll lay out my idea (which isn't new but if someone else wasn't sure how to go about it neither then this should help them too I hope!).

Okay, well here is a number in the base 2 system, and beneath it the power to the base of its location. (Like ones tens hundreds)

0001
3210

If I start at the left of the string, and multiply the 1's or 0's by the number created from 2^(number below current number) and then just add it up, I think it'll give me the number I need.
In this example it's 0 * (2 ^3) + 0 * (2 ^ 2) + 0 * (2^1) + 1 * (2^0) = 1, which is correct!
Okay so I guess I figured it out :P
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Halp ! T.T

Post by tappatekie »

Okay,Im basing this as a serious question.
From my experience, I never used power functions to calculate the actual length of the bits. So instead of
Rebornxeno wrote:

Code: Select all

while (number > pow((double)base, power))
{
	power++;
}
I would try

Code: Select all


//Define the current bit thingy... (you'l see further in the code)
int baseVal = base;

//64 being the maximum length of the bit range (64bit unsigned)
for(int c = 0; c != 65; c++) { 
      //Does c's bit value go outside that of the value to have? 
      if(value >= baseVal) {
             power = c;
             break;
      }

      //Update the base and value
      baseVal *= base;
}
This will basically output the length to the power integer you defined.

An example scenario would be

base = 2; value = 13;
power would be set to 4.

I don't know c++ but I am working from c# code and not sure if you would add pointers in the for loop
Last edited by tappatekie on Mon Dec 05, 2011 8:45 pm, edited 1 time in total.
Rebornxeno
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Thu Jun 23, 2011 11:12 am

Re: Halp ! T.T

Post by Rebornxeno »

Lol I have no idea wtf your talking about. And yeah I think this was a pretty serious question.
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Halp ! T.T

Post by tappatekie »

Rebornxeno wrote:Lol I have no idea wtf your talking about
What part?
Rebornxeno
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Thu Jun 23, 2011 11:12 am

Re: Halp ! T.T

Post by Rebornxeno »

Kind of all of it, I don't know where your really coming from about your answer, as in I don't know if you got what I was asking for. I was having troubles with going from binary to a different number system, not about the length of anything ?

I do appreciate your serious reply though, it was the first one all day. :)
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Halp ! T.T

Post by tappatekie »

Rebornxeno wrote:Kind of all of it, I don't know where your really coming from about your answer, as in I don't know if you got what I was asking for. I was having troubles with going from binary to a different number system, not about the length of anything ?

I do appreciate your serious reply though, it was the first one all day. :)
What numbering system are you having? Hex (if it is a numbering system)?

Edit: No problem :P
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Halp ! T.T

Post by tappatekie »

Oh, and if you have'nt fixed your dilema, I'd be happy to write an app that converts binary to int and hex. But at a later time
Rebornxeno
Chaos Rift Cool Newbie
Chaos Rift Cool Newbie
Posts: 85
Joined: Thu Jun 23, 2011 11:12 am

Re: Halp ! T.T

Post by Rebornxeno »

Well the code in my first post can change the first number, into any numbering system specified. Try it! And you can specify hex values by 0x, so hex can be changed into any numbering system too. Now try to change from a binary number to something else. Whoops! Can't specify a binary number, and that was the problem. I don't mind the numbering system I can change it into, just had to figure HOW to do it.
Wow I'd love that about 2 hours ago ha ha but I think this little snippet turns it into decimal system for me, but thanks again anyways :D

Code: Select all

	int count = ia.size;
	int var = 0;
	for (int g = 0; g < count; g++)
	{
		var += ia.ip[g] * (pow((double)2, (count - g)-1));
	}
tappatekie
Chaos Rift Junior
Chaos Rift Junior
Posts: 204
Joined: Mon Nov 21, 2011 3:01 pm
Current Project: Web browser from scratch
Favorite Gaming Platforms: SNES, PSP, PS1 and 3
Programming Language of Choice: C#
Location: A house near me
Contact:

Re: Halp ! T.T

Post by tappatekie »

Oh okay, and no problem.
User avatar
Ginto8
ES Beta Backer
ES Beta Backer
Posts: 1064
Joined: Tue Jan 06, 2009 4:12 pm
Programming Language of Choice: C/C++, Java

Re: Halp ! T.T

Post by Ginto8 »

Rebornxeno, I just scanned this thread so I don't know if your problem has been solved, but it sounds to me like you're trying to do something similar to base64 encoding, but a little more generic. You can look up base64 implementations (there are plenty out there) and adapt them for more than one possible base.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Post Reply