numbers

Convert A Large Integer To a Hex String In Javascript

╄→гoц情女王★ 提交于 2019-11-29 09:34:05
I need to find a way to convert a large number into a hex string in javascript. Straight off the bat, I tried myBigNumber.toString(16) but if myBigNumber has a very large value (eg 1298925419114529174706173) then myBigNumber.toString(16) will return an erroneous result, which is just brilliant. I tried writing by own function as follows: function (integer) { var result = ''; while (integer) { result = (integer % 16).toString(16) + result; integer = Math.floor(integer / 16); } } However, large numbers modulo 16 all return 0 (I think this fundamental issue is what is causing the problem with

UITextField - Allow only numbers and punctuation input/keypad

主宰稳场 提交于 2019-11-29 09:29:45
问题 I have tried the code below but that only allows for numbers on the keypad to be inputted. My app requires the keypad to use a period/full stop (for money transactions). The code I tried is: - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string { NSCharacterSet *nonNumberSet = [[NSCharacterSet decimalDigitCharacterSet] invertedSet]; if ([string rangeOfCharacterFromSet:nonNumberSet].location != NSNotFound) { return NO; }

Replace numbers in data frame column in R? [duplicate]

无人久伴 提交于 2019-11-29 09:11:39
Possible Duplicate: Replace contents of factor column in R dataframe I have the data.frame df1<-data.frame("Sp1"=1:6,"Sp2"=7:12,"Sp3"=13:18) rownames(df1)=c("A","B","C","D","E","F") df1 Sp1 Sp2 Sp3 A 1 7 13 B 2 8 14 C 3 9 15 D 4 10 16 E 5 11 17 F 6 12 18 I want to replace every entry of the number 8 in the column df1$Sp2 with the number 800. I have tried: test<-replace(df1$Sp2,df1[800,"Sp2"],5) e.g.: df1$Sp2[df1$Sp2 == 8] <- 800 来源: https://stackoverflow.com/questions/11817371/replace-numbers-in-data-frame-column-in-r

Would you use num%2 or num&1 to check if a number is even?

我们两清 提交于 2019-11-29 09:09:14
Well, there are at least two low-level ways of determining whether a given number is even or not: 1. if (num%2 == 0) { /* even */ } 2. if ((num&1) == 0) { /* even */ } I consider the second option to be far more elegant and meaningful, and that's the one I usually use. But it is not only a matter of taste; The actual performance may vary: usually the bitwise operations (such as the logial-and here) are far more efficient than a mod (or div) operation. Of course, you may argue that some compilers will be able to optimize it anyway, and I agree...but some won't. Another point is that the second

oracle varchar to number

丶灬走出姿态 提交于 2019-11-29 09:04:21
How do i convert a oracle varchar value to number eg table - exception exception_value 555 where exception_value is a varchar type I would like to test the value of exception_value column select * from exception where exception_value = 105 instead of select * from exception where exception_value = '105' You have to use the TO_NUMBER function: select * from exception where exception_value = to_number('105') Since the column is of type VARCHAR, you should convert the input parameter to a string rather than converting the column value to a number: select * from exception where exception_value =

Default Number of Decimal Places to Output in PHP

倖福魔咒の 提交于 2019-11-29 08:39:05
I do my php work on my dev box at home, where I've got a rudimentary LAMP setup. When I look at my website on my home box, any numbers I echo are automatically truncated to the least required precision. Eg 2 is echoed as 2, 2.2000 is echoed as 2.2. On the production box, all the numbers are echoed with at least one unnecessary zero, eg 100 becomes 100.0. On both boxes, the PHP version is 5.2.5. Does anyone know offhand if there is a setting I can change which will force PHP to automatically remove any unnecessary zeroes? I don't want to have to go to every place in my code where I output a

Can coordinates of constructable points be represented exactly?

可紊 提交于 2019-11-29 07:50:48
问题 I'd like to write a program that lets users draw points, lines, and circles as though with a straightedge and compass. Then I want to be able to answer the question, "are these three points collinear?" To answer correctly, I need to avoid rounding error when calculating the points. Is this possible? How can I represent the points in memory? (I looked into some unusual numeric libraries, but I didn't find anything that claimed to offer both exact arithmetic and exact comparisons that are

how to loop from 0000 to 9999 and convert the number to the relative string?

久未见 提交于 2019-11-29 07:48:04
i want to get some string, range from 0000 to 9999, that's to say, i want to print the following string: 0000 0001 0002 0003 0004 0005 0006 .... 9999 i tried to use print "\n".join([str(num) for num in range(0, 9999)]) , but failed, i get the following number: 0 1 2 3 4 5 6 ... 9999 i want python to add the prefix 0 automatically, making the number remain 4 bit digits all the time. can anyone give a hand to me? any help appreciated. One way to get what you want is to use string formatting: >>> for i in range(10): ... '{0:04}'.format(i) ... '0000' '0001' '0002' '0003' '0004' '0005' '0006' '0007

Random prime number

自古美人都是妖i 提交于 2019-11-29 07:25:51
问题 How do I quickly generate a random prime number, that is for sure 1024 bit long? 回答1: Generate 1024 random bits. Use a random source that is strong enough for your intended purpose. Set the highest and lowest bits to 1. This makes sure there are no leading zeros (the prime candidate is big enough) and it is not an even number (definitely not prime). Test for primality. If it's not a prime, go back to 1. Alternatively, use a library function that generates primes for you. 回答2: Use a library

Iterate through each digit in a number

╄→гoц情女王★ 提交于 2019-11-29 06:58:05
问题 I am trying to create a program that will tell if a number given to it is a "Happy Number" or not. Finding a happy number requires each digit in the number to be squared, and the result of each digit's square to be added together. In Python, you could use something like this: SQUARE[d] for d in str(n) But I can't find how to iterate through each digit in a number in Java. As you can tell, I am new to it, and can't find an answer in the Java docs. 回答1: You can use a modulo 10 operation to get