int

2 Chars to Short in C

扶醉桌前 提交于 2021-02-19 00:21:18
问题 I've got 2 chars. Char 128 and Char 2 . How do I turn these chars into the Short 640 in C? I've tried unsigned short getShort(unsigned char* array, int offset) { short returnVal; char* a = slice(array, offset, offset+2); memcpy(&returnVal, a, 2); free(a); return returnVal; } But that didn't work, it just displays it as 128 . What's the preferred method? 回答1: I found that the accepted answer was nearly correct, except i'd run into a bug where sometimes the top byte of the result would be 0xff

How do I convert an int to two bytes in C#?

自闭症网瘾萝莉.ら 提交于 2021-02-18 22:16:05
问题 How do I convert an int to two bytes in C#? 回答1: Assuming you just want the low bytes: byte b0 = (byte)i, b1 = (byte)(i>>8); However, since 'int' is 'Int32' that leaves 2 more bytes uncaptured. 回答2: You can use BitConverter.GetBytes to get the bytes comprising an Int32. There will be 4 bytes in the result, however, not 2. 回答3: Another way to do it, although not as slick as other methods: Int32 i = 38633; byte b0 = (byte)(i % 256); byte b1 = (byte)(i / 256); 回答4: Is it an int16? Int16 i = 7;

Storing an int value using Shared preferences

自作多情 提交于 2021-02-18 18:52:57
问题 I have an int "flag" variable , which will have two possible int values , 0 & 1. Main theme of the app here is : Ask user yes or no? If user selects YES, assign int=1. else if Selects No, assign int=0; I am achieving this using: public static int flag; @Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { case R.id.flag0: flag=0; System.err.println("Flag : " + flag); break; case R.id.flag1: flag=1; System.err.println("Flag : " + flag); break; default:

how can i store an int array into string [closed]

瘦欲@ 提交于 2021-02-18 12:10:58
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Improve this question I have an integer array: int a[5]={5,21,456,1,3} I need to store these number into char array so that the char array will have some thing like this: char *s="52145613"; Is there any library function in c for this? 回答1: sprintf do what you need. Little example

how can i store an int array into string [closed]

Deadly 提交于 2021-02-18 12:10:44
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Improve this question I have an integer array: int a[5]={5,21,456,1,3} I need to store these number into char array so that the char array will have some thing like this: char *s="52145613"; Is there any library function in c for this? 回答1: sprintf do what you need. Little example

how can i store an int array into string [closed]

北城余情 提交于 2021-02-18 12:10:14
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 years ago . Improve this question I have an integer array: int a[5]={5,21,456,1,3} I need to store these number into char array so that the char array will have some thing like this: char *s="52145613"; Is there any library function in c for this? 回答1: sprintf do what you need. Little example

Kotlin Compilation Error : None of the following functions can be called with the arguments supplied

二次信任 提交于 2021-02-17 21:19:12
问题 I have a class whose constructor takes 2 int parameters (null values are allowed). Following is the compilation error. None of the following functions can be called with the arguments supplied: public final operator fun plus(other: Byte): Int defined in kotlin.Int public final operator fun plus(other: Double): Double defined in kotlin.Int public final operator fun plus(other: Float): Float defined in kotlin.Int public final operator fun plus(other: Int): Int defined in kotlin.Int public final

string and int concatenation in C++ [duplicate]

假装没事ソ 提交于 2021-02-17 06:41:06
问题 This question already has answers here : How to concatenate a std::string and an int? (23 answers) Closed 4 years ago . string words[5]; for (int i = 0; i < 5; ++i) { words[i] = "word" + i; } for (int i = 0; i < 5; ++i) { cout<<words[i]<<endl; } I expected result as : word1 . . word5 Bu it printed like this in console: word ord rd d Can someone tell me the reason for this. I am sure in java it will print as expected. 回答1: C++ is not Java. In C++, "word" + i is pointer arithmetic, it's not

Unitialized int value always the same (C++)

為{幸葍}努か 提交于 2021-02-16 20:31:27
问题 Given this code: void main() { int x; cout << x; system("pause"); } When I debug this piece of code, it always prints -858993460A. I read that its because VS set this as default value for Unitialized vars. But I also read that in release mode, this should get random value. But everytime I run this code in release mode I get 1772893972A , which Is not changing -> its not random. What is this? Why do I get this value? 回答1: The main is not the real entrypoint of the executable, in general the

Program that generates 20 random numbers and search the array for a number

我是研究僧i 提交于 2021-02-11 15:53:33
问题 I want to make a program that generates 20 random numbers and search the array for a number. If one of the 20 random numbers was typed in the input the output should say "it is here". If the number is not in the ReadLine it should say"Yes it is there".I want to know how to make all 20 random numbers to be able to search. The code right now can only search the number on the right. Even if the input is one of the 20 random numbers except for the one on the right it would say "No it is not here.