Rewrite an even number as 2^a * b [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
I'm looking for an algoritm that takes an even number bigger than 2, and rewrite it as (2 to the power a) times b, with a and b being calculated by the algoritm and b being an odd number.

If x is the input number, divide x by two. If the new number is even, repeat the process, until the outcome is odd. This odd number is b in your formula, while a is the number of iterations you just performed.
Now that you have an idea on the algorithm, try coding it. StackOverflow will not do this for you.

Related

Regarding logical equation on my C programming [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a situation on my C programming here and just wondering whether my solution is the correct way:
I have a LED display with particle count sensor and will show 6 digit of seven segment numbers as the count value. The sensor will give voltage input value. The input is from 0V to 10V. So the range of 0V-10V need to be shown in the display as 000000 to 999999 count.
My solution is:
Display number = Input voltage * 99999.9
For example:
Display number = 10.000*99999.9=999999
Display number = 5.500*99999.9=549999
Display number = 2.300*99999.9=229999
Is this the correct solution? I notice that I will get a lot of 9 on the display value.
The most usable and user friendly solution is to ignore the fact that your most significant digit is capable of displaying up to 9 and simply multiply by 10000 unless you desperately need the maxim resolution in which case simply use a scale factor of 100000 and document that your range is 0-9.99999.
My reasoning is that it is better to either loose one digit in the accuracy across the whole range or clip just the maximum value than to have an error across the entire range.

Calculate & subtract percentage in C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 8 years ago.
Improve this question
Well I know this would be a very easy question ,but i am poor at this concept of Maths.
I know what my final answer should be ,but this answer should come after I subtract some specific percentage from another amount. I want to know what that another amount should be.
Making it a bit simpler :
this is my equation : x - 12% of x should result in 250$. I need to find x.
( Please know if I add 12% to 250 , it will be wrong as 12% of 250 would be different from 12% of what that another amount would be ).
Thank you friends.
This is simply algebra (not necessarily even relevant to C#).
Your equation is:
Solve for :
Therefore this can be calculated in C#:
double x = 250/0.88;
Console.WriteLine(x);
which outputs 284.090909090909

Generating a random double number with one number decimal point [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I have to generate a number between -4.0 and 4.0 including all numbers like 3.4 etc. I have managed to create a random integer but got stuck when creating double - it just returns an integer.
.NET Random class provides a method NextDouble() which can be used in this case. But a workaround for your case would be much easier and faster to implement. Such as:
Dim r As Random = New Random()
Dim d As Double = r.Next(-4, 4) + (r.Next(0, 9) / 10) 'First random next call in desired range, and second is to add the decimal point
Console.WriteLine("Generated Number: {0}", d)
One work around can be that you get a random int between -40 and 40, then divide the result by 10.

Math.Round doesn't behave like i want it to. (X.0xxxxx numbers) [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Quick question.
I'm making a diagram so the numbers i'm passing to the function can be anything (depending on zoom and such). Lets say I want to round the number 3.086948353 to 3 but i still want other numbers like 2.199999999 to round to 2.2.
Currently it just looks like this:
Math.Round(value, 10)
You want to do two things in single shot:
Get the integer value if first digit after decimal is 0
Get the rounded value upto last 2 digits if its first digit after decimal is not 0.
For second option you can use:
newValue = Math.Round(value, 2)
Now comes the first requirement:
Once you get the decimal with 2 digits after decimal, get last two digits:
int decimalValue= (int)((newValue - (int)newValue ) * 100);
if(decimalValue < 10)
{
newValue = Math.Floor(value);
}

How can I reduce the number of figures of a number? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Is there a way to reduce the number of figures of a number?
Example:
double d = 222222222222222224444444444444.0
I want to "serialize" it like 17[2]13[4] for example.
The idea is to reduce the number of "chars" used by the number.
double d = 222222222222222224444444444444.0
You can't have a double that big in the first place.
I want to "serialize" it like 17[2]13[4] for example.
The idea is to reduce the number of "chars" used by the number.
A double only takes 8 bytes regardless of its value. There doesn't seem to be any actual point to this.

Categories