We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,408 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

spliting power value

i want to split the power value
ex:11 pow 10 = (11 pow 7)(11 pow 3) like that i want to split the value
please help me

4
Contributors
11
Replies
3 Days
Discussion Span
3 Months Ago
Last Updated
51
Views
Question
Answered
csss
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Something like this?

static void Main(string[] args)
        {
            int value = 11;
            int power = 8;
            Console.WriteLine(Math.Pow(value, power));
            Console.WriteLine(Math.Pow(value, 2)*Math.Pow(value, 6));

            Console.ReadKey();
        }
ddanbe
Industrious Poster
4,302 posts since Oct 2008
Reputation Points: 2,126
Solved Threads: 724
Skill Endorsements: 26

thank u ddanbe for your suggestion
i have to split the power value by coding itself.
suppose the power value is 33 then
split as 10,10,10,3
like wish i have to split the power value.

pls give some suggestion

csss
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Well, it is just the same :
Math.Pow(value, 33) = Math.Pow(value, 10) * Math.Pow(value, 10)* Math.Pow(value, 10) * Math.Pow(value, 3);
Because 10 + 10 + 10 + 3 = 33
If you like to refresh or study some rules on powers,look here

ddanbe
Industrious Poster
4,302 posts since Oct 2008
Reputation Points: 2,126
Solved Threads: 724
Skill Endorsements: 26

If you're wanting to do what I think you want to do; you want to split your power by units of ten and the remainder?

If so let's take your 33 as an example;

public void Method()
{
    int value = 6;
    int power = 33;

    int iterations = (int)Math.Floor(power / 10); // We want to lose the decimal point
    int remainder = power % 10; // This will return 3. As it returns the remainder of a division operation

    Double result = 1; // Important as we're going to muliply our results together. Starting from 0 would yield 0. Also, we're dealing with "power" so big numbers may result. In these cases, you need to use exponent notation.

    for(int currentIteration = 0;currentIteration < iterations; currentIteration++)
    {
        result = result * Math.Pow(value, 10);
    }

    result = result * Math.Pow(value, remainder);

    Console.WriteLine("Result is: {0}", result);
    Console.WriteLine("Actual   : {0}", Math.Pow(value, power));

    Console.ReadLine();
}

It's important to note, that you won't be able to display this in normal integer format for large numbers as the structures simply aren't big enough even with unsigned 64-bit addressing (unless you converted it to a string...)

Ketsuekiame
Veteran Poster
1,195 posts since May 2010
Reputation Points: 553
Solved Threads: 153
Skill Endorsements: 9

Thank u Ketsuekiame for your suggestion.
its working perfect but i want non exponential format.
From above program,the result is return as exponent format but i want non exponent format(i.e)without exponential format.
Because decryption process want the actual data.

pls give some suggestion.

csss
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Hi csss, the only way to retrieve the numeric value is to use the BigInteger class. This will let you have a theoretically infinitely large number.

However, the caveat to this is that everything you use will be limited to a minimum of .NET 4 framework. If you cannot use .NET 4 or above I'm afraid you're out of luck.

Additionally, rather than use Math.Pow you will need to use BigInteger.Pow but this should work for you.

Ketsuekiame
Veteran Poster
1,195 posts since May 2010
Reputation Points: 553
Solved Threads: 153
Skill Endorsements: 9

There is code for a biginteger class, if you need it, search the posts here for biginteger.

tinstaafl
Nearly a Posting Virtuoso
1,336 posts since Jun 2010
Reputation Points: 360
Solved Threads: 235
Skill Endorsements: 14

tinstaafl, I just did a search for a BigInteger class (not .net 4) and couldn't find anything. Do you have a link to the post in question? I'd be curious to see how they implemented it in C#

Ketsuekiame
Veteran Poster
1,195 posts since May 2010
Reputation Points: 553
Solved Threads: 153
Skill Endorsements: 9

If you need to code your own biginteger look at ddanbe's last post here

It seems though we keep going in circles, csss gets good suggestions, and rather than implementing them, asks the same question a different way and gets the same suggestions.

tinstaafl
Nearly a Posting Virtuoso
1,336 posts since Jun 2010
Reputation Points: 360
Solved Threads: 235
Skill Endorsements: 14

thank tinstaafl for your suggestion
the biginteger perform well for long value

once again thank you so much

csss
Newbie Poster
19 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

you're welcome. please mark this solved, if you have what you need.

tinstaafl
Nearly a Posting Virtuoso
1,336 posts since Jun 2010
Reputation Points: 360
Solved Threads: 235
Skill Endorsements: 14
Question Answered as of 3 Months Ago by Ketsuekiame, tinstaafl and ddanbe

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0873 seconds using 2.68MB