integer

Convert floating point variable to integer?

杀马特。学长 韩版系。学妹 提交于 2019-12-19 05:13:54
问题 The shell script shown below will show a warning if the page takes more than 6 seconds to load. The problem is that the myduration variable is not an integer. How do I convert it to integer? myduration=$(curl http://192.168.50.1/mantisbt/view.php?id=1 -w %{time_total}) > /dev/null ; \ [[ $myduration -gt 1 ]] && echo "`date +'%y%m%d%H%M%S' It took more than 6 seconds to load the page http://192.168.50.1/mantisbt/view.php?id=1 回答1: Assuming $myduration is a decimal or integer $ myduration=6.5 $

factorial of big numbers with strings in c++

…衆ロ難τιáo~ 提交于 2019-12-19 03:58:27
问题 I am doing a factorial program with strings because i need the factorial of Numbers greater than 250 I intent with: string factorial(int n){ string fact="1"; for(int i=2; i<=n; i++){ b=atoi(fact)*n; } } But the problem is that atoi not works. How can i convert my string in a integer. And The most important Do I want to know if the program of this way will work with the factorial of 400 for example? 回答1: There's a web site that will calculate factorials for you: http://www.nitrxgen.net

Computing greatest common denominator in python

与世无争的帅哥 提交于 2019-12-19 03:24:19
问题 If you have a list of integers in python, say L = [4,8,12,24] , how can you compute their greatest common denominator/divisor (4 in this case)? 回答1: One way to do it is: import fractions def gcd(L): return reduce(fractions.gcd, L) print gcd([4,8,12,24]) 来源: https://stackoverflow.com/questions/3640955/computing-greatest-common-denominator-in-python

how to put a string into an integer array c++

╄→гoц情女王★ 提交于 2019-12-18 18:30:07
问题 I have a string that contains what ever the user has input string userstr = ""; cout << "Please enter a string "; getline (cin, userstr); The string is then stored in userstr, I then want the string to be stored in a integer array where each character is a different element in the array. I have created a dynamic array as the following: int* myarray = new int[sizeof(userstr)]; However how do I then get my string into that array? 回答1: You can access each element in your string using the []

how to convert byte value into int in objective-c

独自空忆成欢 提交于 2019-12-18 18:05:10
问题 Please tell me how to convert bytes to NSInteger/int in objective-c in iPhone programming? 回答1: What do you mean by "Bytes"? If you want convert single byte representing integer value to int (or NSInteger) type, just use "=": Byte b = 123; NSInteger x; x = b; as Byte (the same as unsigned char - 1 byte unsigned integer) and NSInteger (the same as int - 4 bytes signed integer) are both of simple integer types and can be converted automatically. Your should read more about " c data types " and

Select incremented integer

百般思念 提交于 2019-12-18 16:55:07
问题 I want to know if it's possible to select incremented integer from mysql table? and if it does possible, how can I achieve that? My case is, I have a bunch of data and I need to do INSERT INTO newtable ... SELECT somefield FROM sometable . However, there is one field on newtable called counter that I need it in incremented integer, eg: row #1: counter=1 row #2: counter=2 row #3: counter=3 row #4: counter=4 row #5: counter=5 row #6: counter=6 ... and so on... I can do this using simple php

Select incremented integer

北战南征 提交于 2019-12-18 16:54:50
问题 I want to know if it's possible to select incremented integer from mysql table? and if it does possible, how can I achieve that? My case is, I have a bunch of data and I need to do INSERT INTO newtable ... SELECT somefield FROM sometable . However, there is one field on newtable called counter that I need it in incremented integer, eg: row #1: counter=1 row #2: counter=2 row #3: counter=3 row #4: counter=4 row #5: counter=5 row #6: counter=6 ... and so on... I can do this using simple php

how to split 64bit integer to two 32bit integers

非 Y 不嫁゛ 提交于 2019-12-18 16:32:24
问题 I want to split a 64bit integer into two 32bit integers: var bigInt = 0xffffff; var highInt = bigInt >> 8 // get the high bits 0xfff var lowInt = bigInt // cut of the first part (with &)? console.log(highInt); // 0xfff console.log(lowInt); // 0xfff // set them together again var reBigInt = (highInt << 8) + lowInt; Unfortunately neither getting the highInt nor getting the lowInt works... Could somebody give me the answer how I need to use the bitwise operators? regards 回答1: EDIT JavaScript

Number (integer or decimal) to array, array to number (integer or decimal) without using strings

核能气质少年 提交于 2019-12-18 13:33:50
问题 Requirement: Convert input integer or decimal to an array and convert array of integers which may include a decimal to a number. Restriction: Do not use string methods or convert input or output to a string during the procedure (a self-imposed restriction followed throughout each version of the code composed). Context and use cases BigInt in available in some browsers, though not a BigDecimal . The conversion from integer or decimal to array and array to integer or decimal should be possible

how to cast an array of char into a single integer number?

你。 提交于 2019-12-18 13:28:20
问题 i'm trying to read contents of PNG file. As you may know, all data is written in a 4-byte manner in png files, both text and numbers. so if we have number 35234 it is save in this way: [1000][1001][1010][0010]. but sometimes numbers are shorter, so the first bytes are zero, and when I read the array and cast it from char* to integer I get wrong number. for example [0000] [0000] [0001] [1011] sometimes numbers are misinterpreted as negative numbers and simetimes as zero! let me give you an