How to find 9s complement of a given decimal number? - twos-complement

Given decimal number=12
One way to find 9s complement is to simply find 10s complement and subtract 1. By this method I get answer=87.
However can i solve this problem by first finding the equivalent of 12 in base 9 number system which would be 13. Now if I find 9s complement of this number using the formula r^n -N answer would be 81-12.
Please suggest what's wrong ?

Related

C++ Xtensor increase floating point significant numbers

I am building a neural network and using xtensor for array multiplication in feed forward. The network takes in xt::xarray<double> and outputs a decimal number between 0 and 1. I have been given a sheet for expected output. when i compare my output with the provided sheet, I found that all the results differ after exactly 7 digits. for example if the required value is 0.1234567890123456, I am getting values like 0.1234567-garbage-numbers-so-that-total-numbers-equal-16, 0.1234567993344660, 0.1234567221155667.
I know I can not get that exact number 0.1234567890123456 due to floating point math. But how can I debug/ increase precision to be close to that required number. thanks
Update:
xt::xarray<double> Layer::call(xt::xarray<double> input)
{
return xt::linalg::dot(input, this->weight) + this->bias;
}
for code I am simply calling this call method a bunch of times where weight and bias are xt::xarray<double> arrays.

How to do twos compliment with larger decimal values?

I am trying to do twos compliment of the following: 34-11.
After trying to solve the problem myself and then getting the answer from a calculator I am doing it completely wrong after following many tutorials.
I converted 34 and 11 to binary first getting 100010 and 1011 respectively. I then got 0101 by 1s notation and adding 1 after.
Finally, 100010 + 0101 = 100111.
From what I can find this is not the correct answer. I would appreciate if someone could walk me through it, thanks.

Find occurence probabilities in finite O-1 regex

I'm searching a fastest algorithm to compute probabilities of occurrence of 0-1 in regex.
I explain ..
For instance I have this regex 0*110+10* where + mean at least one time. more over i know that the size of the sequence will be of 6.
Thus I can produce all possibilities:
110001
110010
110100
011010
011001
001101
So with this enumeration i know that the first one have 0.5 probability to be 1, the second 5/6 to be 1. But to compute these probabilities i must enumerate all possibilities. Does exist an algorithm which can give faster the occurence probabilities ?
Thanks in advance

Can we validate Min and Max Value for a floating Number using RegExp?

Hi I know that we can validate Min and Max Length of a number using Regex.
But can we validate Min and Max Value for a floating point number using the same?
Min Value : 0.00
Max Value :100,000,000.00
Could anyone please just apply Min and Max Value to following Regex:
^(?=.*\d)(?!.*?\.[^.\n]*,)\d*(,\d*,?)*(\.\d*)?$
Above Regex matches a floating number with optional decimal point and commas.
Regex is for strings. You try to compare floats. It's just not the right tool. It's worse than eating your soup with a fork. It's like writing on paper with a knife or cutting your hair with a teaspoon.
Look here for a solution with positive integers without thousands separator :
Using regular expressions to compare numbers
I leave the task to you to extend that solution to using floats, thousands separator and negative numbers.
I guess this should help you. This regex will match 0.00 to 100,000,000.00 upto 2 decimal places.
^(:?(?=[1])(10{0,8})|(?=[^0])(\d{1,8})|0)\.[0-9]{1,2}$
But keep in mind that its always best to compare numbers numerically that using regex.
Here is the link to verify it.

Number format construct?

Outside the binary 01010, octal 01122, decimal integer 1234 and hexadecimal 0xFF, does any one have any idea or trick how to build a new number format? For example, 0x11AEGH has it's range from 0 - 9 to A - H. I'm going to build password generator, so it would be very helpful if anyone can put something on it that might help.
Firstly, Is there any function which can do this? Basically I want to convert 0x11AEGH to binary, octal, integer and so on...
Formatting a number in an N-ary system requires two things: an alphabet, and an ability to obtain results of integer division + the remainder.
Consider formatting a number in a base-26 system using the Latin alphabet. Repeatedly obtain the remainder R of division by 26, pick letter number R, and add it to the front of the number that you are formatting. Integer-divide the number by 26, and use it in the next step of the algorithm. Stop when you reach zero.
For example, if you print 1234 in base-26, you can do it like this:
1234 % 26 is 12. Add M; 1234/26 is 47
47 % 26 is 21. Add V; 47 / 26 is 1
1 % 26 is 1. Add B. 1 / 26 is zero; stop.
So 1234 in base-26 is BVM.
To convert back, start from the front, and sequentially subtract the designated "zero" (A in case of the above example) from each digit, like this:
B-A is 1. Result is 1
V-A is 21. Result is 1*26+21, which is 47
M-A is 12. Result is 47*26+12, which is 1234.
You can probably use functions like Long.parseLong(String representation, int radix) and Long.toString(long value, int radix) as they are in Java. Other languages may also have the similar features.
This approach restricts the maximal possible radix (base) and you have no control over the characters representing different digits (alphanumeric chars are used). However it is a ready solution without any extra coding.