integer

Convert array of string javascript to array of integer javascript

ε祈祈猫儿з 提交于 2019-12-22 19:26:05
问题 I have an array, var array = ["1","2","3","4","5"]; then I need to convert to var array = [1,2,3,4,5]; How can i convert? 回答1: Map it to the Number function: var array = ["1", "2", "3", "4", "5"]; array = array.map(Number); array; // [1, 2, 3, 4, 5] 回答2: The map() method creates a new array with the results of calling a provided function on every element in this array. The unary + acts more like parseFloat since it also accepts decimals. Refer this Try this snippet: var array = ["1", "2", "3"

why Integer.parseInt(“11111111111111111111111111111111”,2) throws exception in java? [closed]

China☆狼群 提交于 2019-12-22 18:18:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . why does Integer.parseInt("11111111111111111111111111111111",2) throw java.lang.NumberFormatException: For input string: "11111111111111111111111111111111" In java integer is 32 bit, I expect a valid return value, what is going wrong here ? 回答1: Integer is truly 32 bit, but one bit is used for positive/negative

Random number generator - variable length

旧巷老猫 提交于 2019-12-22 13:47:12
问题 Currently my program (see below) generates random strings (made of numbers) from 8 - 12 characters in length. public static string GenerateNewCode(int CodeLength) { string newCode = String.Empty; int seed = unchecked(DateTime.Now.Ticks.GetHashCode()); Random random = new Random(seed); // keep going until we find a unique code ` do { newCode = random.Next(Convert.ToInt32(Math.Pow(10, CodeLength - 1)), Convert.ToInt32(Math.Pow(10, CodeLength) - 1)).ToString("0000"); } while (!ConsumerCode

In JavaScript, how is integer represented in storage layout?

淺唱寂寞╮ 提交于 2019-12-22 12:56:15
问题 JavaScript comes with 64bit float numbers for all numeric literals, and the storage layout and range is regulated under ITEE 754. On the other hand, I learned that the float has a range of ± ~10^-323.3 to ~10^308.3 and an as-reliable-as-possible precision. Integer has a range of -2^53 - 2^53 and a reliable precision. ITEE 754 explains the behavior of float numbers but I get confused about the integer in JS. How is the range of precision generated from the 64bit data format? [Solved] The value

How To Append an Integer (with an Integer) in C++

让人想犯罪 __ 提交于 2019-12-22 10:57:30
问题 I was wondering if anyone could tell me how to append an integer (with another integer) in C++. Basically, if I have an int with this the value 67, how would I append it with the number 4 so the integer is now 674? Thanks in advance! 回答1: Multiply first by ten to the power of digit number of second and add the other . Example: 63 and 5 63*10=630 630+5 =635 Example: 75 and 34 75*100=7500 7500+34=7534 int i1=75; int i2=34; int dn=ceil(log10(i2+0.001)); //0.001 is for exact 10, exact 100, ...

Serial message to integer on Arduino

筅森魡賤 提交于 2019-12-22 10:05:15
问题 I want my Arduino to receive an integer through the serial communication. Can you help me with this? It should be in a form like: int value = strtoint(Serial.read()); 回答1: There are several ways to read an integer from Serial , largely depending on how the data is encoded when it is sent. Serial.read() can only be used to read individual bytes so the data that is sent needs to be reconstructed from these bytes. The following code may work for you. It assumes that serial connection has been

Flooring numbers in JavaScript: ~~n, n|0 or Math.floor(n)?

与世无争的帅哥 提交于 2019-12-22 09:37:03
问题 I've recently discovered some other ways to remove the fractional part of numeric values in JavaScript other than Math.floor(n) , specifically the double bitwise NOT operator ~~n and performing a bitwise or with 0 n|0 . I'd like to know what are the difference between these approaches and what the different scenarios are where one method is recommended over another. 回答1: Be clear to the next person looking at your code and use Math.floor() . The performance gain of 1%-40% isn't really worth

Python 3: Tkinter: How to change Entry.get() into an integer

三世轮回 提交于 2019-12-22 09:10:56
问题 I am coding a simple program which converts imperial units into metric units . However, when I use an Entry.get() command, I need to convert it to an integer and when I try to do that I get this error: Traceback (most recent call last): File "C:/Users/Bill/converter.py", line 18, in <module> conversion=int(e.get()) ValueError: invalid literal for int() with base 10: '' I tried running an extremely basic version of what I was doing (which is written below), but that still caused the same error

Reading strings, integers etc from files using fscanf

旧街凉风 提交于 2019-12-22 08:57:59
问题 I'd like your help with understanding how should I do the following: I have a file that contains integers separated by spaces ' '. I need to read all integers, sort them and write them as a strings to another file. I wrote a code, but I read char by char, put the word in an char sub_arr [Max_Int] and when I met ' ', I put these chars, now one string, after atoi-ing it into another Main int array,until reaching the end of the file, string by string, and then I sorted and itoa-ing them and

Calculate the smallest integer with k bits set that is greater than another integer x?

半城伤御伤魂 提交于 2019-12-22 08:16:28
问题 I want to calculate the smallest integer with exactly k bits set, that is greater than another integer x . For example if x = 1001010 then for k=2 , the answer should be 1010000 for k=4 , the answer should be 1001011 and for k=5 the answer is 1001111 I think that one would need to set at least as many bits as the leftmost bits set in the integer x , and then choose between setting the MSB-side bit adjacent to the next leftmost set bit in x , or setting the next leftmost set bit and then look