How to convert hexadecimal NSData into decimal NSData? - ios

How to convert long hexadecimal number371d2a3f041fb4ab210fe7567b3a041f9072089790f9b34139fb2df7301ebcad
into long decimal number 24928736809215721890296636138640601514085104766215587836409400141363575438509 in iOS?

What you are looking for is a type that can store an arbitrary-sized integer. There is no native type for this in Foundation, but a Google search for "bigint in objective-c" should give you some ideas.

Related

How to cast hex string as hex integer?

I'm using BLE plugin, which requires to present the values as list of hex number(e.g. [0x20,0x11,0x06,0x6D]).
I was able to get a list of hex strings using int.toRadixString (['0x20','0x11','0x06','0x6D']), but didn't find a way to convert those strings into hex integers.
I'm looking for something like int demicalToHex(int demical) or similar function.
Thanks in advance.
There's no such thing as a hex number. What it needs is a list of integers (List<int>).
In the same way that you have [0x20,0x11,0x06,0x6D] you could equally write that as [32, 17, 6, 109]. Sometimes, it's convenient to think about integers in their decimal representation or their hex representation (or octal, or binary...), but as far as the compiler is concerned, they are just integers.
Just use an array of integers (not strings).

Swift - Convert string to double without scientific notation(exponents)

I have a string which is in exponents. For example my string is
"-4.17182640083098e-31"
I have an array of values like this. I want to use this to draw chart.
The graph accepts double values only to plot it. When I convert it to double using Double(str) and using it in graph is not working because the graph library not accepting exponents.
So I converted this to decimal value the result is
-0.0000000000000000000000000000011803449813502
So I again converted this decimal to double it gives the same -4.17182640083098e-31 with exponents notation.
So can't use this is graph. So please suggest a way to convert this to double without the exponents/scientific notations. Thanks in advance.

iOS: Convert a string from little endiand to big endian

I got a string in little endian that I would like to convert in big endian.
This "647b" should become "7b64". How can I do this in iOS (C++ code welcome)?
PS: I am deriving the string from a NSData object.
You didn't say how you were converting your data into a NSString, so I have to make some assumptions here.
NSStrings (and CFStringRefs, which are toll free bridged) have encodings. Many iOS devs don't need to keep in mind that their strings are UTF8Encoded.
[If you look at the list of string encodings from Apple (CoreFoundation & Foundation), you'll see some of them do specify little-endian and big-endian.
And probably the best way to do what you are trying to do is something like this:
// load it as UTF16 big endian
NSString *str = [NSString alloc] initWithData:yourDataObject encoding:NSUTF16BigEndianStringEncoding];
That line of code I found in this related question.

iOS:convert hex data to integer format

i am doing corebluetooth application and able to receive the data from the peripheral in the hex format i need to parse the data to integer format and is there any method to convert the data to integer format from hex format please help Below values iam getting
NSstring *data is
011f6d000000160000000000040507010500054607db051705173a0600053d
Nslog(#"data is Ð`#PpPT`}°QpQs")
And also please help if there is any method for converting the data to the string also.
Define a struct with all the correct types and order. Point the struct to the data. Then just access the items via the struct elements. Be careful with the types, it is probably best to use well defined types such as int8_t, uint8_t, uint16_t, int16_t, etc to insure the correct element size. You will want a "packed" struct, not alligned to the CPU alignment size.

Converting SHA1 hash Hex string to decimals using objective C on iPhone

I am a beginner to developing apps on the iPhone and I am trying to convert a 40 character SHA1 hash in hex to decimals. i have been looking around and the largest integer type in unsigned long long but it's not enough. I tried looking at NSDecimalNumber but it doesn't have Hex function.
Well I guess there is no way of doing so. I would have to change it to a string instead.

Resources