int

How to convert a list of multiple integers into a single integer?

好久不见. 提交于 2020-01-11 08:03:12
问题 How do I convert a list in Python 3.5 such as: x=[1, 3, 5] to an int of 135 (a whole int)? 回答1: If you have a list of int s and you want to join them together, you can use map with str to convert them to strings, join them on the empty string and then cast back to int s with int. In code, this looks like this: r = int("".join(map(str, x))) and r now has the wanted value of 135 . This, of course, is a limited approach that comes with some conditions. It requires the list in question to contain

Printing pointer addresses in C [two questions]

谁说我不能喝 提交于 2020-01-11 01:46:31
问题 I know that my questions are very simple but googleing them didn't get me any useful results... They'r probably too simple!! No. 1 char* createStr(){ char* str1 = malloc(10 * sizeof(char)); printf("str1 address in memory : %p\n", &str1); return str1; } int main(void){ char* str2 = createStr(); printf("str2 address in memory : %p\n", &str2); } Result: str1 address in memory : 0x7fffed611fc8 str2 address in memory : 0x7fffed611fe8 Why are the addresses different in and out of the createStr()

Why are the fast integer types faster than the other integer types?

这一生的挚爱 提交于 2020-01-10 06:46:51
问题 In ISO/IEC 9899:2018 (C18) is stated under 7.20.1.3: 7.20.1.3 Fastest minimum-width integer types 1 Each of the following types designates an integer type that is usually fastest 268) to operate with among all integer types that have at least the specified width. 2 The typedef name int_fastN_t designates the fastest signed integer type with a width of at least N. The typedef name uint_fastN_t designates the fastest unsigned integer type with a width of at least N. 3 The following types are

How to check if a int var contains a specific number

情到浓时终转凉″ 提交于 2020-01-10 03:57:07
问题 How to check if a int var contains a specific number I cant find a solution for this. For example: i need to check if the int 457 contains the number 5 somewhere. Thanks for your help ;) 回答1: 457 % 10 = 7 * 457 / 10 = 45 45 % 10 = 5 * 45 / 10 = 4 4 % 10 = 4 * 4 / 10 = 0 done Get it? Here's a C implementation of the algorithm that my answer implies. It will find any digit in any integer. It is essentially the exact same as Shakti Singh's answer except that it works for negative integers and

Hashcode of an int

假装没事ソ 提交于 2020-01-09 09:34:23
问题 What is the hashcode of a primitive type, such as int? for example, let's say num was an interger. int hasCode = 0; if (num != 0) { hasCode = hasCode + num.hashCode(); } 回答1: For the hashCode of an int the most natural choice is to use the int itself. A better question is what to use for the hashCode of a long since it doesn't fit into the int -sized hashcode. Your best source for that—and all hashCode -related questions—would be Effective Java. 回答2: Taken from the Integer.class source code:

Hashcode of an int

我的未来我决定 提交于 2020-01-09 09:33:13
问题 What is the hashcode of a primitive type, such as int? for example, let's say num was an interger. int hasCode = 0; if (num != 0) { hasCode = hasCode + num.hashCode(); } 回答1: For the hashCode of an int the most natural choice is to use the int itself. A better question is what to use for the hashCode of a long since it doesn't fit into the int -sized hashcode. Your best source for that—and all hashCode -related questions—would be Effective Java. 回答2: Taken from the Integer.class source code:

Count leading zeroes in an Int32

拈花ヽ惹草 提交于 2020-01-09 07:24:05
问题 How do I count the leading zeroes in an Int32? So what I want to do is write a function which returns 30 if my input Int32 is 2, because in binary I have 0000000000000010. 回答1: Let's take the number 20 as an example. It can be stated in binary as follows: 00000000000000000000000000010100 First we "smear" the most significant bit over the lower bit positions by right shifting and bitwise-ORing over itself. 00000000000000000000000000010100 or 00000000000000000000000000001010 (right-shifted by 1

String convert to Int and replace comma to Plus sign

喜夏-厌秋 提交于 2020-01-09 07:12:10
问题 Using Swift, I'm trying to take a list of numbers input in a text view in an app and create a sum of this list by extracting each number for a grade calculator. Also the amount of values put in by the user changes each time. An example is shown below: String of: 98,99,97,96... Trying to get: 98+99+97+96... Please Help! Thanks 回答1: Use components(separatedBy:) to break up the comma-separated string. Use trimmingCharacters(in:) to remove spaces before and after each element Use Int() to convert

int to binary python

时光怂恿深爱的人放手 提交于 2020-01-07 08:13:08
问题 This question is probably very easy for most of you, but i cant find the answer so far. I'm building a network packet generator that goes like this: class PacketHeader(Packet): fields = OrderedDict([ ("head", "\x00"), ("headpad", "\x00"), ("headlen", "\x1a\x00" ), ("presentflag", "\x2e"), ("timestamp", "\x43\x10\x58\x16\xa1\x01\x00\x00"), ("flag", "\x03"), ("Sequencenum", "\x04\x00"), ]) Later, I call my class and send the packet like this: send(PacketHeader(Sequencenum=257)) send

Two 16 bit ints to One 32 bit float value

随声附和 提交于 2020-01-07 04:37:19
问题 I am able to extract values from modbus as 16-bit shorts (unsigned) or as ints (should be treated as 16-bit words). I am tasked to combine two values to create a single 32 bit float value using java. some example values I observed using a gui program: int + int = float 0 + 16256 = 1 0 + 17096 = 100 0 + 17097 = 100.5 0 + 17530 = 1000 8192 + 17530 = 1000.5 I attempted bit wise operators but that didn't seem to do the trick. leaves me scratching my head! 回答1: You can use Float.intBitsToFloat(int