I am trying to get the MCC and MNC for the blackberry device. I am using this code:
int code = RadioInfo.getCurrentNetworkIndex();
int mcc = RadioInfo.getMCC(code);
int mnc = RadioInfo.getMNC(code);
String mccS = Integer.toString(mcc);
String mncS = Integer.toString(mnc);
I am getting values, byt when searching for the right values on the internet, I found that the MCC and MNC differ from the ones I obtained in this code. For example for the operator alfa in lebanon, I should obtain:
Mcc = 415 and MNC = 1
I am obtaining:
Mcc = 1045 and MNC = 1
Why Is that happening? Is this the right way to get the MCC and MNC? Thanks in advance
you get mcc by using
String mcc = Integer.toHexString(RadioInfo.getMCC(RadioInfo.getCurrentNetworkIndex()));
In my experience it's quite messy on BB. Based on experiments accross different networks and devices, we use
// manual says MCCs can be identified as either 260 or 26F; actually for us it is decimal so we convert it to hexa
// this replaceAll "f" stuff is strange, but seems to work: MNC==1F becomes 1 which nicely matches RadioInfo.getMNC(RadioInfo.getCurrentNetworkIndex());
int mcc = Integer.parseInt(TextUtils.replaceAll(Integer.toHexString(GPRSInfo.getCellInfo().getMCC()),"f", ""));
You need to convert the number.
The MNC and MCC will be returned as decimal numbers, whereas MCCs and MNCs will be listed as hexadecimal numbers. For example, a BlackBerry smartphone operating on the AT&T® mobile network will return MCC=784 (hex 310) and MNC=896 (hex 380).
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/1467358/How_To_-_Determine_the_MCC_and_MNC_of_the_current_network.html?nodeid=1467359&vernum=0
Related
I've been trying to create a very simple ERC20 token with truffle in the rinkeby network. I placed the following code into my .sol file but the max supply doesnt seem to match.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "#openzeppelin/contracts/token/ERC20/ERC20.sol";
contract Artytoken is ERC20 {
address public admin;
uint private _totalSupply;
constructor() ERC20('ArtyToken', 'AATK') {
admin = msg.sender;
_totalSupply = 1000000;
_mint(admin, _totalSupply);
}
}
In my Metamask address shows that i own "0.000000000001" and I've seen that in Etherscan it shows that the max total supply its "0.000000000001". What im doing wrong?
Thank you in advance! :)
The EVM does not support decimal numbers (to prevent rounding errors related to the network nodes running on different architectures), so all numbers are integers.
The ERC-20 token standard defines the decimals() function that your contract implements, effectively shifting all numbers by the declared number of zeros to simulate decimals.
So if you wanted to mint 1 token with 18 decimals, you'd need to pass the value 1000000000000000000 (18 zeros). Or as in your case, 1 million tokens (6 zeros) with 18 decimals is represented as 1000000000000000000000000 (24 zeros). Same goes the other way around, 0.5 of a token with 18 decimals is 500000000000000000 (17 zeros).
You can also use underscores (they effectively do nothing but visually separate the value) and scientific notation to mitigate human error while working with such large amount of zeros:
// 6 zeros and 18 zeros => 24 zeros
_totalSupply = 1_000_000 * 1e18;
I am trying to convert NSString to long but I am getting garbage value. Below is my code :
long t1 = [[jsonDict valueForKeyPath:#"detail.amount"]doubleValue] * 1000000000000000000;
long t2 = [[jsonDict valueForKeyPath:#"detail.fee"]doubleValue] * 10000000000000000;
NSLog(#"t1: %ld",t1);
NSLog(#"t2: %ld",t2);
detail.amout = 51.74
detail.fee = 2.72
O/P :
t1: 9223372036854775807 (Getting Garbage value here)
t2: 27200000000000000 (Working fine)
Thanks in advance.
Each number types (int, long, double, float) has limits. For your long 64 bit (because your device is 64bit) number the upper limit is :9,223,372,036,854,775,807 (see here: https://en.wikipedia.org/wiki/9,223,372,036,854,775,807)
In your case, 51.74 * 1,000,000,000,000,000,000 =
51,740,000,000,000,000,000
While Long 64bit only has a maximum of
9,223,372,036,854,775,807
So an overflow happens at 9,223,372,036,854,775,808 and above. Which is what your calculation evaluates into.
Also to note, that what you are doing will also cause problem if you only cater for 64bit long range, because what happens when your app runs on a 32bit (like iPhone 5c or below)?
Generally a bad idea to use large numbers, unless you're doing complex maths. If number accuracies are not critical, then you should consider simplifying the number like 51,740G (G = Giga). etc.
It's because you're storing the product to long type variables t1 and t2.
Use either float or double, and you'll get the correct answer.
Based on C's data types:
Long signed integer type. Capable of containing at least the
[−2,147,483,647, +2,147,483,647] range; thus, it is at least 32
bits in size.
Ref: https://en.wikipedia.org/wiki/C_data_types
9223372036854775807 is the maximum value of a 64-bit signed long. I deduce that [[jsonDict valueForKeyPath:#"detail.amount"]doubleValue] * 1000000000000000000 is larger than the maximum long value, so when you cast it to long, you get the closest value that long can represent.
As you read, it is not possible with long. Since it looks like you do finance math, you should use NSDecimalNumber instead of double to solve that problem.
I am asking for ways to calculate the square root of any given number in ios, Objective C. I have inserted my way to do it using log. the logic was. ex : find the square root of 5
X = √5
then
log10X = log10(√5)
this means
log10X = log10(5)/2;
then should get the value of log10(5) and divide it from 2 and after that shoud get the antilog of that value to search X.
so my answer is in Objective C is like below (as an ex: I'm searching the square root of 5)
double getlogvalue = log10(5)/2; // in here the get the value of 5 in log10 and divide it from two.
//then get the antilog value for the getlogvalue
double getangilogvalue = pow(10,getlogvalue);
//this will give the square root of any number. and the answer may include for few decimal points. so to print with two decimal point,
NSLog(#"square root of the given number is : %.02f", getantilogvalue);
If anyone have any other way/answers. to get the square root of any given value , add please add and also suggestions for above answer is also accepted.
This is open for swift developers too. please add there answers also, becasue this will help to anyone who want to calculate the square root of any given number.
The sqrt function (and other mathematical functions as well) is
available in the standard libraries on all OS X and iOS platforms.
It can be used from (Objective-)C:
#include "math.h"
double sqrtFive = sqrt(5.0);
and from Swift:
import Darwin // or Foundation, Cocoa, UIKit, ...
let sqrtFive = sqrt(5.0)
In Swift 3,
x = 4.0
y = x.squareRoot()
since the FloatingPoint protocol has a squareRoot method and both Float and Double comply with the FloatingPoint protocol. This should be higher performance than the sqrt() function from either Darwin or Glibc, since the code it generates will be from the LLVM built-in square root, so no function call overhead on systems with hardware square root machine code.
I have two cards which contains a hex value, I am struggling to find out what kind of algorithm is used ti get the decimal value.
8HEX from chip: 0b98c44a Printed on card: 3491308370
8HEX from chip: 0c96425c Printed on card: 812204602
does any one of you number experts in here find out how it is done, you helped me with this before :)
The relation between the numbers seems to be that the bits of every byte has been reversed.
When you print first pair in binary they are:
11010000 00011001 00100011 01010010 = 3491308370
00001011 10011000 11000100 01001010 = 0x0b98c44a
The second pair is:
00110000 01101001 01000010 00111010 = 812204602
00001100 10010110 01000010 01011100 = 0x0c96425c
If you want to know how to convert one number to the other, you should mention which programming language you are using.
I need a well tested Regular Expression (.net style preferred), or some other simple bit of code that will parse a USA/CA phone number into component parts, so:
3035551234122
1-303-555-1234x122
(303)555-1234-122
1 (303) 555 -1234-122
etc...
all parse into:
AreaCode: 303
Exchange: 555
Suffix: 1234
Extension: 122
None of the answers given so far was robust enough for me, so I continued looking for something better, and I found it:
Google's library for dealing with phone numbers
I hope it is also useful for you.
This is the one I use:
^(?:(?:[\+]?(?<CountryCode>[\d]{1,3}(?:[ ]+|[\-.])))?[(]?(?<AreaCode>[\d]{3})[\-/)]?(?:[ ]+)?)?(?<Number>[a-zA-Z2-9][a-zA-Z0-9 \-.]{6,})(?:(?:[ ]+|[xX]|(i:ext[\.]?)){1,2}(?<Ext>[\d]{1,5}))?$
I got it from RegexLib I believe.
This regex works exactly as you want with your examples:
Regex regexObj = new Regex(#"\(?(?<AreaCode>[0-9]{3})\)?[-. ]?(?<Exchange>[0-9]{3})[-. ]*?(?<Suffix>[0-9]{4})[-. x]?(?<Extension>[0-9]{3})");
Match matchResult = regexObj.Match("1 (303) 555 -1234-122");
// Now you have the results in groups
matchResult.Groups["AreaCode"];
matchResult.Groups["Exchange"];
matchResult.Groups["Suffix"];
matchResult.Groups["Extension"];
Strip out anything that's not a digit first. Then all your examples reduce to:
/^1?(\d{3})(\d{3})(\d{4})(\d*)$/
To support all country codes is a little more complicated, but the same general rule applies.
Here is a well-written library used with GeoIP for instance:
http://highway.to/geoip/numberparser.inc
here's a method easier on the eyes provided by the Z Directory (vettrasoft.com),
geared towards American phone numbers:
string_o s2, s1 = "888/872.7676";
z_fix_phone_number (s1, s2);
cout << s2.print(); // prints "+1 (888) 872-7676"
phone_number_o pho = s2;
pho.store_save();
the last line stores the number to database table "phone_number".
column values: country_code = "1", area_code = "888", exchange = "872",
etc.