numbers

number out of string in java

蓝咒 提交于 2019-11-28 03:38:35
问题 I have something like "ali123hgj". i want to have 123 in integer. how can i make it in java? 回答1: Use the following RegExp (see http://java.sun.com/docs/books/tutorial/essential/regex/): \d+ By: final Pattern pattern = Pattern.compile("\\d+"); // the regex final Matcher matcher = pattern.matcher("ali123hgj"); // your string final ArrayList<Integer> ints = new ArrayList<Integer>(); // results while (matcher.find()) { // for each match ints.add(Integer.parseInt(matcher.group())); // convert to

Convert A Large Integer To a Hex String In Javascript

岁酱吖の 提交于 2019-11-28 03:02:31
问题 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

How do you set, clear and toggle a single bit in JavaScript?

久未见 提交于 2019-11-28 02:48:22
How to set, clear, toggle and check a bit in JavaScript? cletus To get a bit mask: var mask = 1 << 5; // gets the 6th bit To test if a bit is set: if ((n & mask) != 0) { // bit is set } else { // bit is not set } To set a bit: n |= mask; To clear a bit: n &= ~mask; To toggle a bit: n ^= mask; Refer to the Javascript bitwise operators . I want to add some things (with thanks to @cletus) function bit_test(num, bit){ return ((num>>bit) % 2 != 0) } function bit_set(num, bit){ return num | 1<<bit; } function bit_clear(num, bit){ return num & ~(1<<bit); } function bit_toggle(num, bit){ return bit

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

心不动则不痛 提交于 2019-11-28 02:34:04
问题 This question already has answers here : Closed 7 years ago . 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) 回答1: e.g.: df1$Sp2[df1$Sp2 == 8] <-

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

半腔热情 提交于 2019-11-28 02:33:07
问题 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

MATLAB generate random numbers

陌路散爱 提交于 2019-11-28 02:28:13
Hi I am trying to generate random numbers in MATLAB with a random MEAN value. For example, if I use e = mean(rand(1000,1)) the answer for e will always be close to 0.5 . What I want is for the value of e (mean) to be random, so that e can be 0.1, 0.2, 0.3, etc... Is it correct for me to use e = mean( unifrnd(0,1,[1000,1]) ) ? Thanks Perhaps you want to generate normally distributed random numbers X~N(0,1) with randn . Then you can change the mean and standard deviation to be random. As an example: N = 1000; mu = rand*10 - 5; %# mean in the range of [-5.0 5.0] sigma = randi(5); %# std in range

oracle varchar to number

ぐ巨炮叔叔 提交于 2019-11-28 02:25:57
问题 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' 回答1: You have to use the TO_NUMBER function: select * from exception where exception_value = to_number('105') 回答2: Since the column is of type VARCHAR, you should convert the input parameter

Javascript Number Prototype Set Value Directly [duplicate]

允我心安 提交于 2019-11-28 02:22:42
This question already has an answer here: Javascript using prototype how can I set the value of “this” for a number? 3 answers I try to set a number directly from a prototype method. Usually, a new value is returned. this of a number object, is also an object. But I guess not a reference. (?) I have this: Number.prototype.bitSet = function(bit) { return this | (1<<bit); }; But want this: Number.prototype.bitSet = function(bit) { this.value = this | (1<<bit); }; this.value is a pseudo property. Becuase this sould be a reference of the number and without that, you'll overwrite it. But the

JComboBox to list age

雨燕双飞 提交于 2019-11-28 02:22:27
Purpose: JComboBox to list down ages that a user can select I realize that I need an array of integers. What part of the Math functions in Java will allow me to easily do that? The list of numbers will be from 1-100 in sequential order. Adel Boutros I don't quite understand why you need the Math functions. This would work: List<Integer> age = new ArrayList<Integer>(); for (int i = 1; i <= 100; ++i) { age.add(i); } JComboBox ageComboBox = new JComboBox(age.toArray()); You don't need any math functions. Look up JComboBox in the java docs and you'll find a .addItem function. It can take a String

How to generate random numbers with no repeat javascript

℡╲_俬逩灬. 提交于 2019-11-28 02:17:17
I am using the following code which generates random number between 0 to Totalfriends, I would like to get the random numbers but they should not be repeated. Any idea how? This is the code I am using FB.getLoginStatus(function(response) { var profilePicsDiv = document.getElementById('profile_pics'); FB.api({ method: 'friends.get' }, function(result) { // var result =resultF.data; // console.log(result); var user_ids="" ; var totalFriends = result.length; // console.log(totalFriends); var numFriends = result ? Math.min(25, result.length) : 0; // console.log(numFriends); if (numFriends > 0) {