integer

Why does the most negative int value cause an error about ambiguous function overloads?

纵饮孤独 提交于 2019-12-28 01:55:10
问题 I'm learning about function overloading in C++ and came across this: void display(int a) { cout << "int" << endl; } void display(unsigned a) { cout << "unsigned" << endl; } int main() { int i = -2147483648; cout << i << endl; //will display -2147483648 display(-2147483648); } From what I understood, any value given in the int range (in my case int is 4 byte) will call display(int) and any value outside this range will be ambiguous (since the compiler cannot decide which function to call). It

bitwise AND in Javascript with a 64 bit integer

余生长醉 提交于 2019-12-27 17:40:49
问题 I am looking for a way of performing a bitwise AND on a 64 bit integer in JavaScript. JavaScript will cast all of its double values into signed 32-bit integers to do the bitwise operations (details here). 回答1: Javascript represents all numbers as 64-bit double precision IEEE 754 floating point numbers (see the ECMAscript spec, section 8.5.) All positive integers up to 2^53 can be encoded precisely. Larger integers get their least significant bits clipped. This leaves the question of how can

bitwise AND in Javascript with a 64 bit integer

≯℡__Kan透↙ 提交于 2019-12-27 17:40:11
问题 I am looking for a way of performing a bitwise AND on a 64 bit integer in JavaScript. JavaScript will cast all of its double values into signed 32-bit integers to do the bitwise operations (details here). 回答1: Javascript represents all numbers as 64-bit double precision IEEE 754 floating point numbers (see the ECMAscript spec, section 8.5.) All positive integers up to 2^53 can be encoded precisely. Larger integers get their least significant bits clipped. This leaves the question of how can

Get int from String, also containing letters, in Java

吃可爱长大的小学妹 提交于 2019-12-27 17:39:14
问题 How can I get the int value from a string such as 423e - i.e. a string that contains a number but also maybe a letter? Integer.parseInt() fails since the string must be entirely a number. 回答1: Unless you're talking about base 16 numbers (for which there's a method to parse as Hex), you need to explicitly separate out the part that you are interested in, and then convert it. After all, what would be the semantics of something like 23e44e11d in base 10? Regular expressions could do the trick if

Get int from String, also containing letters, in Java

陌路散爱 提交于 2019-12-27 17:38:12
问题 How can I get the int value from a string such as 423e - i.e. a string that contains a number but also maybe a letter? Integer.parseInt() fails since the string must be entirely a number. 回答1: Unless you're talking about base 16 numbers (for which there's a method to parse as Hex), you need to explicitly separate out the part that you are interested in, and then convert it. After all, what would be the semantics of something like 23e44e11d in base 10? Regular expressions could do the trick if

Print an int in binary representation using C

我是研究僧i 提交于 2019-12-27 10:53:09
问题 I'm looking for a function to allow me to print the binary representation of an int. What I have so far is; char *int2bin(int a) { char *str,*tmp; int cnt = 31; str = (char *) malloc(33); /*32 + 1 , because its a 32 bit bin number*/ tmp = str; while ( cnt > -1 ){ str[cnt]= '0'; cnt --; } cnt = 31; while (a > 0){ if (a%2==1){ str[cnt] = '1'; } cnt--; a = a/2 ; } return tmp; } But when I call printf("a %s",int2bin(aMask)) // aMask = 0xFF000000 I get output like;

“copy” elements of array in order into an “int”? C [closed]

别来无恙 提交于 2019-12-27 06:11:08
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . It may be a really simple question, but I need to copy two int values that are in array[0] and array[1] into a single integer. As instance if array[0]=1

Convert string to int in C++ [duplicate]

谁说胖子不能爱 提交于 2019-12-25 19:45:07
问题 This question already has answers here : How can I convert a std::string to int? (15 answers) Closed 5 years ago . I have a string xxxxxxxxxxxxxxxxxxx I am reading the string into a structure of smaller strings, and using substr to parse it. I need to convert one of those string types to integer. atoi is not working for me,. any ideas? it says cannot convert std::string to const char* Thanks #include<iostream> #include<string> using namespace std; void main(); { string s="453" int y=atoi(S);

From random integers to an actual String

拟墨画扇 提交于 2019-12-25 18:58:35
问题 This is a code that takes in an array of all the printing characters of the ASCII table. I am trying to make it so that any String message in the form of integers (e.g. String "aba" that is converted 97098097 can be put back into its original String form. 100101101 can be taken and made back into "dee". I've really tried hard with this method but it does not seem to be working, especially when it comes to numbers and such please help me. It is in Java by the way and I am using Eclipse. public

Arbitrary precision bit manipulation (Objective C)

和自甴很熟 提交于 2019-12-25 18:12:40
问题 I need to do bit operations on representations of arbitrary precision numbers in Objective C. So far I have been using NSData objects to hold the numbers - is there a way to bit shift the content of those? If not, is there a different way to achieve this? 回答1: Using NSMutableData you can fetch the byte in a char , shift your bits and replace it with -replaceBytesInRange:withBytes: . I don't see any other solution except for writing your own date holder class using a char * buffer to hold the