How to add two 40 digit numbers in Objective-C and Android - android

I want to know how to add two 40 digit numbers both in Objective C and Android.
Example:
4000000000000000000000000000000000000000000000000000000000
+5000000000000000000000000000000000000000000000000000000000
How to store and where to store these values?
What is the solution for this?

In Android you can use the BigInteger class for arbitrary sized integers. As for storing them, depends on what you need to store them for, but android has a number of storage options described here that should be able to store these large integers.

in case of objective-c, following code is been used to do the calculation
NSDecimalNumber *aNumber = [NSDecimalNumber decimalNumberWithString:#"4000000000000000000000000000000000000000"];
NSDecimalNumber *bNumber = [NSDecimalNumber decimalNumberWithString:#"2000000000000000000000000000000000000000"];
NSDecimalNumber *cNumber = [aNumber decimalNumberByAdding:bNumber];
NSLog(#"%#", cNumber);
here we use the NSDecimalNumber.

Related

Use mobilenet V1 model on Android

I'm trying to use the model used on this tutorial in an Android app. I wanted to modify DetectorActivity.java and TensorFlowMultiBoxDetector.java found here but it seems like i miss some parameters as imageMean, imageStd, inputName, outputLocationsName and outputScoresName.
From what I understand, input name is the name of the input for the model and both outputs are the names for the position and score output, but what do imageMean and imageStd stand for ?
I don't need to use the model with a camera, I just need to detect objects on bitmaps.
Your understanding of input/output names seems correct. They are tensorflow node names that can receive input and will contain the outputs at the end. imageMean and imageStd are used to scale the RGB values of the image to the mean of 0 and the standard deviation of 1. See the 8 lines starting from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/android/src/org/tensorflow/demo/TensorFlowMultiBoxDetector.java#L208
The TensorFlow android demo app you are referring to has been updated. It now supports MobileNets. Check it out at github: commit 53aabd5cb0ffcc1fd33cbd00eb468dd8d8353df2.

Handling integers bigger than Long with Firebase and android

I am developing an app with Firebase, it is a game in which certain scores are shared between players and can grow without a limit. I tried storing them as a String, but then I could not order them with orderByChild for the leaderboard. How can I handle this problem?
You could store the number as a linked list, with each node in the list representing each digit. Be careful with the order; putting the last number (the ones digit) in the list first, makes math with the linked list easier, while the other direction makes it easier to return the nodes in the list to a number on the screen.
To store integers which are big in size java provides a BigInteger Class to handle those numbers. I will suggeat you to use that first read the concept and then try to findout what you exactly want!
Check this one BigInteger

What to use for large numbers with precision?

I need a way to store large numbers with precision. Let's say I want to have 1'234'567'890.123456 in a variable. I was thinking about using Strings ( though it's not recommended ) but I believe there must be a much better way to do this.
BigDecimal gives you numbers with arbitrary precision. It is serialisable so you could save it like that, or use toString() and save that representation.
Take a look at BigDecimal. They are Immutable, arbitrary-precision signed decimal numbers.

check number between two numbers Android

How can i check if a number is between two other numbers in Android
if(number1.matches("[1024-65535]+"));
else{
One way to solve your problem is to convert all values that need to be compared into ints. Then the comparison is trivial.

Android TextViews. Is parametrization possible? Is binding to model possible?

I am new to both Android and Stack Overflow. I have started developing and Android App and I am wondering two things:
1) Is it possible to parametrize a TextView? Lets say I want to render a text message which states something like: "The user age is 38". Lets suppose that the user age is the result of an algorithm. Using some typical i18n framework I would write in my i18n file something like "The user age is {0}". Then at run time I would populate parameters accordingly. I haven't been able to figure out how to do this or similar approach in Android.
2) Let's suppose I have a complex object with many fields. Eg: PersonModel which has id, name, age, country, favorite video game, whatever. If I want to render all this information into a single layout in one of my activities the only way I have found is getting all needed TextViews by id and then populate them one by one through code.
I was wondering if there is some mapping / binding mechanism in which I can execute something like: render(myPerson, myView) and that automatically through reflection each of the model properties get mapped into each of the TextViews.
If someone has ever worked with SpringMVC, Im looking for something similar to their mechanism to map domain objects / models to views (e.g. spring:forms).
Thanks a lot in advanced for your help. Hope this is useful for somebody else =)
bye!
In answer to #1: You want String.format(). It'll let you do something like:
int age = 38;
String ageMessage = "The user age is %d";
myTextView.setText(String.format(ageMessage, age));
The two you'll use the most are %d for numbers and %s for strings. It uses printf format if you know it, if you don't there's a quicky tutorial in the Formatter docs.
For #2 I think you're doing it the best way there is (grab view hooks and fill them in manually). If you come across anything else I'd love to see it.

Categories

Resources