integer

Convert binary string to integer in php

感情迁移 提交于 2020-01-11 11:04:23
问题 In php how do I convert a string "1010101010" into the integer value represented by this binary number? eg "10" would go to 2, "101" would go to 5 回答1: Use bindec() function to convert from binary to decimal: $value = bindec("10101011010101"); 回答2: Try the bindec() function. 来源: https://stackoverflow.com/questions/4424746/convert-binary-string-to-integer-in-php

Convert binary string to integer in php

纵然是瞬间 提交于 2020-01-11 11:02:48
问题 In php how do I convert a string "1010101010" into the integer value represented by this binary number? eg "10" would go to 2, "101" would go to 5 回答1: Use bindec() function to convert from binary to decimal: $value = bindec("10101011010101"); 回答2: Try the bindec() function. 来源: https://stackoverflow.com/questions/4424746/convert-binary-string-to-integer-in-php

Is it possible to use egrep to match numbers within a range?

僤鯓⒐⒋嵵緔 提交于 2020-01-11 07:45:10
问题 Is there a way to grep / egrep between two sets of numbers? egrep "SomeText [19999-22000]" /some/file.txt It's not returning the values. I expect: SomeText 19999 ffuuu SomeText 20001 ffuuu SomeText 21000 ffuuu 回答1: regex is not the right tool for math stuff (although sometimes it can do), in your case, try the awk: awk '$2>=19999 && $2<=22000' file 回答2: You can use the range function , with awk awk '$2=="19999",$2=="22000"' file SomeText 19999 ffuuu SomeText 20001 ffuuu SomeText 21000 ffuuu

JavaScript pack integers and calculate arbitrary precision float:

时光毁灭记忆、已成空白 提交于 2020-01-11 06:48:10
问题 I need to do the following in JavaScript and so far been unable to find solutions to do it seamlessly: Grab two integers in a specific order and pack them like Python's struct module. This packed value, (bonus for supporting different endianness than host) will be turned into a 64 bit float (double). They must be arbitrary thus I might get an exponent representation of the integer (say, they could be 0xdeadbeef and 500): In exp form: 1.0883076389305e-311 1.0883076389305000 * 10 ^ - 311 I need

how to calculate (a times b) divided by c only using 32-bit integer types even if a times b would not fit such a type

别说谁变了你拦得住时间么 提交于 2020-01-11 03:15:08
问题 Consider the following as a reference implementation: /* calculates (a * b) / c */ uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c) { uint64_t x = a; x = x * b; x = x / c; return x; } I am interested in an implementation (in C or pseudocode) that does not require a 64-bit integer type. I started sketching an implementation that outlines like this: /* calculates (a * b) / c */ uint32_t muldiv(uint32_t a, uint32_t b, uint32_t c) { uint32_t d1, d2, d1d2; d1 = (1 << 10); d2 = (1 << 10); d1d2 =

Is integer division always equal to the floor of regular division?

南笙酒味 提交于 2020-01-10 20:25:10
问题 For large quotients, integer division ( // ) doesn't seem to be necessarily equal to the floor of regular division ( math.floor(a/b) ). According to Python docs (https://docs.python.org/3/reference/expressions.html - 6.7), floor division of integers results in an integer; the result is that of mathematical division with the ‘floor’ function applied to the result. However, math.floor(648705536316023400 / 7) = 92672219473717632 648705536316023400 // 7 = 92672219473717628 '{0:.10f}'.format

Display integer at compile time in static_assert()

假如想象 提交于 2020-01-10 18:21:27
问题 Here is a simplified version of what I'm trying to do enum First { a, b, c, nbElementFirstEnum, }; enum Second { a, b, c, nbElementSecondEnum, }; static_assert( First::nbElementFirstEnum == Second::nbElementSecondEnum, "Not the same number of element in the enums."); /*static_assert( First::nbElementFirstEnum == Second::nbElementSecondEnum, "Not the same number of element in the enums." + First::nbElementFirstEnum + " " + Second::nbElementSecondEnum);*/ But I would like to be able to print

Efficiently generating unique pairs of integers

北慕城南 提交于 2020-01-10 10:16:05
问题 In MATLAB, I would like to generate n pairs of random integers in the range [1, m] , where each pair is unique. For uniqueness, I consider the order of the numbers in the pair to be irrelevant such that [3, 10] is equal to [10, 3] . Also, each pair should consist of two distinct integers; i.e. [3, 4] is ok but [3, 3] would be rejected. EDIT: Each possible pair should be chosen with equal likelihood. (Obviously a constraint on the parameters is that n <= m(m-1)/2 .) I have been able to

Is `double` guaranteed by C++03 to represent small integers exactly?

妖精的绣舞 提交于 2020-01-10 04:55:11
问题 Does the C++03 standard guarantee that sufficiently small non-zero integers are represented exactly in double ? If not, what about C++11? Note, I am not assuming IEEE compliance here. I suspect that the answer is no , but I would love to be proved wrong. When I say sufficiently small , I mean, bounded by some value that can be derived from the guarantees of C++03, and maybe even be calculated from values made available via std::numeric_limits<double> . EDIT: It is clear (now that I have

PHP - Force integer conversion to float with three decimals

不想你离开。 提交于 2020-01-10 04:28:05
问题 I am trying to convert a big array of numbers to a specific format which is +/-NNN.NNN. So, if I have these numbers: $numbers1 = array(-1.23, 0.3222, 10, 5.54); I want their final format to be $numbers2 = array(-001.023, +000.322, +010.000, +005.054); I am trying to do it like this: foreach ($numbers1 as $n) { $fnum = abs(number_format((float)$n, 3, '.', '')); if ($fnum>0 && $fnum<10) { $fnum = '00'.$fnum; } else if ($fnum >= 10 && $fnum<100) { $fnum = '0'.$fnum; } if ($n>0) $fnum = '+'.$fnum