What is the fastest way to find if there is any odd digit in a given natural number - numbers

I am seeking to find the fastest way to find if there is any odd digit in any given natural number.
I seeking an expression, not a program or function or any kind of loop.
The expression should return true if there is at least one odd digit at any position of the number, return false if there is none.
eg 412 should return true as it as 1 (odd) digit at second position.
and 4820426 should return false as there is no any odd digit at any position.
Hint: use of bitwise operator does make sense
PS: this is not a homework, but this just got clicked into my mind after solving other problems.

Related

How can I print the ascii value of an input in Brainfuck?

What I want to do is for a Brainfuck code to print out the ascii value of the input. For example, typing in an input of "a" will give an output of 97. The python equivalent of this is print(ord(input())). What I'm thinking is that once I get the input with the , command, I can split the input value's digits into separate cells, and then print each cell individually. What I mean by this is let's say you type in an input of a. The , command will store the ascii value of a in the first cell(cell 0), which is 97 in this case. Then I run some algorithm that will split the 97 into its individual digits. So, in this case, cell 1 will have a value of 0(because 97 has a hundred digit of 0), cell 2 will have a value of 9, and cell 3 will have a value of 7. Then we can add 48 to each of those cells(0 has an ascii value of 48) and print each cell individually, starting from cell 1(the hundreds place). The problem I'm facing is writing the digit separation algorithm. I can't seem to make it work. My idea is to subtract 100 from the original number until that number is less than 100 while keeping track of how many times 100 has been subtracted, then repeatedly subtract 10, and finally we are left with the ones place. But the problem with this idea is that I have no idea how to track if the number falls under 100 or 10. Any suggestions or ideas? Thanks for the help in advance.
What you are trying to implement is called "divmod". divmod is a function that divides two numbers (in your case positive integers) and stores the result and the remainder. Implementations for this in brainfuck exist: Divmod algorithm in brainfuck
Good luck!

How to determine an Overflow in a 4 bit ripple-carry adder-substractor?

What function that depends by following variablesc (First Operand's sign[0/1], Second Operand's sign[0/1], Result's sign[0/1] and Operation sign[0/1]) can identify an overflow in the 4-bit ripple-carry adder/substractor?
P.S.
An overflow occurs only if:
the sum of two positive numbers yields a negative result, the sum has overflowed.
the sum of two negative numbers yields a positive result, the sum has overflowed.
I only know the method with checking the 2 last carries but it seems that there's another method.
Your PS already contains the correct logic formula written in prose (for addition). Remember that a number is "positive" if its sign bit is zero and the number is negative if its sign bit is one.1 This means you can translate "yields a negative result" to "the operation sign is 1". You can translate the other statements about operands or results to logic conditions in the same way, to finally derive a general boolean formula.
1: I know that zero is neither positive nor negative, but treating zero as positive does no harm in this case.

Using Matlab to find output at specified input values

spacing_Pin = transpose(-27:0.0001:2);
thetah_2nd = Phi_intrp3(ismembertol(spacing_Pin,P_in2nd));
With this code, I want to evaluate Phi_intrp3at indices where spacing_Pinis equal to P_in2nd
I know I have asked similar questions before. And I have got some really helpful answers already. But in this case they do not seem to apply. P_in2ndhas only 40 entries, whereas spacing_Pinhas far more. Therefore I cannot consider the absolute value of the difference of spacing_Pinand P_in2ndto find out where they are closest to equal.
so P_in2ndhas values between -25.9747 and -0.0147. The decimals have 4 digits after the dot, but these are sometimes rounded by Matlab (format short). That's the catch, I think, P_in2nd is not found in spacing_Pin. The result is an empty matrix.
Here's the first 5 entries of P_in2nd:
-25,9747431735299
-24,9747431735299
-23,9947431735299
-23,0047431735299
-22,0047431735299
Now, I want to evaluate ¸Phi_intrp3at these values. For this purpose I can change spacing_Pin, but not P_in2nd. For example, when I search for the first entry of P_in2ndin spacing_Pin, I find that entry 10254 = -25,9747000000000. So I want to evaluate Phi_intrp3at this input entry.
Is there a way of doing this?

How to remove the negative symbol for values in expression in ssrs

FormatCurrency(
(SUM(iif(IsNothing(Fields!Planned.Value),0,Fields!Planned.Value))-(SUM(iif(IsNothing(Fields!Actuals.Value),
iif(IsNothing(Fields!Forecasts.Value),0,Fields!Forecasts.Value),
iif(Fields!Actuals.Value=0,iif(IsNothing(Fields!Forecasts.Value),
0,
Fields!Forecasts.Value),Fields!Actuals.Value))))),
iif(Parameters!DecimalDigits.Value=1,1,iif(Parameters!DecimalDigits.Value=2,2,0)),0,0,0)
)
this is my expression which is returning negative values and how to remove this negative sign in front of the number
The easiest way is to turn the expression around. For instance, if
Planned - Actual
is giving you negative numbers and you want positive numbers then maybe you want
Actual - Planned
Otherwise you could just take the whole expression away from zero to reverse the sign:
0 - <expression>
Or if you really want to kill the negative sign regardless, then use Absolute - this returns the value as a positive number regardless
Abs(<expression>)
I would also remove the formatting part of the expression and put that into the Format property. Almost everything in SSRS can be an expression, so you don't have to do everything in the Value expression.

Why do we have "is not a Number" (isNan) functions?

Many languages have an isNaN() function. I am asking myself: why check for not being a number?
Is the reason purely logical or is it faster to check for not a number instead of is a number?
Note that this is a pure question of understanding. I know that I can negate isNaN() to achieve an isNumber() function for example.
However I am searching for a reason WHY we are checking for not a number?
In computing, NaN (Not a Number) is a
value of numeric data type
representing an undefined or
unrepresentable value, especially in
floating-point calculations.
Wiki Article
Because Not a Number is a special case of an expression.
You can't just use 0 or -1 or something like that because those numbers already have meanings.
Not a Number means something went awry in a calculation and a valid number cannot be computed out of it.
It's on the same line of thinking as having null. Sure, we could assign an arbitrary numerical value to mean null but it would be confusing and we'd hit all sorts of weird errors on corner cases.
'Not a Number' is the result of specific floating point calculations. It's not about "hey, is this variable holding 120 or "abc"?'
isThisCaseExceptional seems more reasonable to me than isEverythingNormal because I'm likely to write
possible_number = some_calculation();
if (inNaN(possible_number)) handle_the_surprise;
// .. keep going
instead of
possible_number = some_calculation();
if (inANumber(possible_number)) {
// .. keep going
} else {
// handle the surprise
}
The check is for whether it is not a number, because the assumption is that it is a number. NaN is the exceptional case when you're expecting a numeric value, so it makes sense to me that it is done this way. I'd rather check for isNaN infrequently than check if a value isNum frequently, after all.
It is a way to report an error condition (mathematically undefined or outside of technical limits).
Many languages have special representations if the result of a computation is not representable by a number, for example NaN and Inf. So isNaN() checks, if a result is actually a number or the special marker for NaN.
NaNs are used for:
Nonreal or undefined values.
Error handling. Initializing a variable with NaN allows you to test for NaN and make sure it has been set with a valid value.
Objects that ignore a member or property. For example, WPF uses NaN to represent the Width and Height of visual elements that do not define their own size.