integer

Hashing function for four unsigned integers (C++)

▼魔方 西西 提交于 2019-12-20 10:23:41
问题 I'm writing a program right now which produces four unsigned 32-bit integers as output from a certain function. I'm wanting to hash these four integers, so I can compare the output of this function to future outputs. I'm having trouble writing a decent hashing function though. When I originally wrote this code, I threw in a simple addition of each of the four integers, which I knew would not suffice. I've tried several other techniques, such as shifting and adding, to no avail. I get a hash,

uint32_t vs uint_fast32_t vs uint_least32_t

夙愿已清 提交于 2019-12-20 09:48:41
问题 I saw different types of definition of an integer in stdint.h . I'll take unsigned 32-bit integer as an example. uint32_t means clearly an unsigned integer of 32 bits. That's the one I always use. uint_fast32_t and uint_least32_t : What's the difference with uint32_t and when should I use them instead of uint32_t ? And now, I saw uintX_t where X is 24, 40, 48 and 56. It happens in my code that I have to work with 48 and 56-bit integers. As an example, I suppose uint24_t is define as something

Testing if a variable is an integer [duplicate]

醉酒当歌 提交于 2019-12-20 09:36:08
问题 This question already has answers here : Test whether string is a valid integer (11 answers) Closed 5 years ago . I would like to test if my variable $var is actually an integer or not. How can I please do that? 回答1: As long as you're using bash version >=3 you can use a regular expression: [[ $a =~ ^-?[0-9]+$ ]] && echo integer While this bash FAQ mentions inconsistencies in the bash regex implementation in various bash 3.x ( should the regex be quoted or not ), I think in this case, there

In C# integer arithmetic, does a/b/c always equal a/(b*c)?

只谈情不闲聊 提交于 2019-12-20 09:32:28
问题 Let a, b and c be non-large positive integers. Does a/b/c always equal a/(b * c) with C# integer arithmetic? For me, in C# it looks like: int a = 5126, b = 76, c = 14; int x1 = a / b / c; int x2 = a / (b * c); So my question is: does x1 == x2 for all a, b and c? 回答1: Let \ denote integer division (the C# / operator between two int s) and let / denote usual math division. Then, if x,y,z are positive integers and we are ignoring overflow , (x \ y) \ z = floor(floor(x / y) / z) [1] = floor((x /

PHP number: decimal point visible only if needed

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 08:59:10
问题 I'd like to know if exists some function to automatically format a number by it's decimal, so if I have: <?php // $sql_result["col_number"] == 1,455.75 number_format ($sql_result["col_number"], 2, ".", ""); // will return 1455.75 // $sql_result["col_number"] == 1,455.00 number_format ($sql_result["col_number"], 2, ".", ""); // could I get 1455 instead of 1455.00? ?> so my answer is if does exist some way to remove the decimals if I have DECIMAL data forma in my DB only when it's round? Or

How to pick up only integer data from an ArrayList of String

夙愿已清 提交于 2019-12-20 07:48:45
问题 I read a text file and put the data into an ArrayList of String . The data is like China 12351235123 Korea 123532523 USA 12341235123 I just need those integer data as an integer to find the first digit of the integers. I know how to find the first digit, but I don't know how I can pick up only the integer data. 回答1: I am assuming that your ArrayList is of type String . replaceAll() will take out anything that isn't a number(0-9) ArrayList<String> countrys = new ArrayList<String>(); countrys

Fibonacci calculation in Java Longs shows up negative

帅比萌擦擦* 提交于 2019-12-20 07:47:35
问题 My Fibonacci calculator works fine, but when going up to higher numbers the result comes up negative, as it would if it was an Integer over its max value. It is working with a cache java.util.Map<Integer, Long> . Everything that goes into the Map is exactly what is expected, but when printing it out I get e.g. for 291: -784134397488903422 According to http://www.maths.surrey.ac.uk/hosted-sites/R.Knott/Fibonacci/fibCalcX.html, it should be:

How to use Bitxor for Double Numbers?

末鹿安然 提交于 2019-12-20 07:44:34
问题 I want to use xor for my double numbers in matlab,but bitxor is only working for int numbers. Is there a function that could convert double to int in Matlab? 回答1: The functions You are looking for might be: int8(number) , int16(number) , uint32(number) Any of them will convert Double to an Integer, but You must pick the best one for the result You want to achieve. Remember that You cannot cast from Double to Integer without rounding the number. If I understood You correcly, You could create a

How can I preserve leading zeros when reading a number and printing it later?

微笑、不失礼 提交于 2019-12-20 07:42:45
问题 I want to cout an integer starting 0. For example, 0123456789. But when I print it out, it only display 123456789 instead of 0123456789 . How can I solve this problem? Below is my sample code: sample.txt 0125961349 01359395930 019349130 I parse 1 of the contact number into an object, eg: 019349130. hence: cout << cp.contactNum << endl; and the final result is 19349130 This is not the result I want. And you can see I have different length for the integer, I cannot use the leading zero solution

Subsets of a given Set of Integers whose sum is a Constant N : Java

瘦欲@ 提交于 2019-12-20 05:59:17
问题 Given a set of integers, how to find a subset that sums to a given value...the subset problem ? Example : S = {1,2,4,3,2,5} and n= 7 Finding the possible subsets whose sum is n. I tried to google out found many links,but were not clear. How can we solve this in java and what is the data structure to be used and its complexity ? 回答1: I wont give you any code, but explain how it works. Run a loop from 0 to (2^k-1) For each value in 1, a 1 in its binary representation indicates that this value