integer

How do I specify a non-negative number at the type level, if I shouldn't be using unsigned?

橙三吉。 提交于 2019-12-24 01:44:31
问题 In a Going Native 2013 talk, the panel had suggested avoiding unsigned integer types when specifying variables that "can't be negative". 12:15: "Use signed integers unless you need 2's compliment arithmetic or a bit pattern." 12:55: "Use ints until you have a reason not to. Don't use unsigned unless you are fiddling with bit patterns, and never mix signed and unsigned." 42:45: "Whenever you mix signed and unsigned numbers you get trouble. The rules are just very surprising, and they turn up

Integer construction variations

只愿长相守 提交于 2019-12-24 01:43:26
问题 Hey all, I ran into an interesting occurrence and am looking for an explanation. In Java 1.6: Integer a = new Integer(5); Integer b = new Integer(5); System.out.println(a == b); Integer c = 5; Integer d = 5; System.out.println(c == d); I get: false true In Eclipse I checked in the debugger. a and b are different objects, while c and d are the same objects (but different from a and b ). Can anyone clue me in on what's going on under the hood? Is this JVM magic? Realizing that a Integer(5) is

PHP storing multiple integer variables in 1 variable?

时光怂恿深爱的人放手 提交于 2019-12-24 00:57:53
问题 I'm creating a php script which creates a random number which is 7 digits long and doesn't contain 0's, the only problem with this is that I have to call the function rand 7 times and store every number generated in a different variable, but I was wondering how I could put these numbers together in a variable instead of adding them together something along the lines of $security_number = $1&&$2&&$3 and so on. thanks in advance. 回答1: I think I know what you are trying to achieve. You need the

How to show integer from activity in XML?

Deadly 提交于 2019-12-23 23:15:03
问题 I use XML output in my app. So basically the main activity just tells the android to show the XML layout of main. But what if I have in the activity code defined integer variable and I want this integer variable also be shown on the display? How do I PUSH the integer variable to the XML??? From main XML reference to other strings in XML is easy - @string/app_name ... but how do I use the integer variable from the activity? 回答1: Presumably you're showing some text in a TextView . You can

Why is parseInt() not converting my String of numbers correctly?

断了今生、忘了曾经 提交于 2019-12-23 21:17:47
问题 I have some logic within a function that takes a string of numbers called digits like so: 6145390195186705543 I then attempt to convert with parseInt() like so: parseInt(digits) The result of: digits = parseInt(digits); is 6145390195186705000 Can someone help me understand why this is the case? and how i can get an accurate conversion? 回答1: This is another version of "broken" floating point math: Javascript uses 64 bits to store numbers as small as the size of an atom up to the number of

What does the compiler at casting integer constants?

ⅰ亾dé卋堺 提交于 2019-12-23 21:06:53
问题 Using the following macro: #define MIN_SWORD (signed int) 0x8000 In e.g. the following expression: signed long s32; if (s32 < (signed long)MIN_SWORD)... is expected to do the following check: if (s32 < -32768) One some compilers it seems to work fine. But on some other compiler the exprssion is evaluated as: if (s32 < 32768) My question: How is a ANSI-C compiler supposed to evaluate the following expression: (signed long) (signed int) 0x8000 ? It seems that on some compilers the cast to `

Input several numbers from array and each one number check for integer or not

吃可爱长大的小学妹 提交于 2019-12-23 19:34:12
问题 everyone! I hope someone can help me figure out something in C language. This is my first seriously homework in IT, I have no experience and I'm learning in e-studies, so teacher help isn't very available. I need to develop console application in C language. User need to input 10 integer numbers, if insert number isn't integer, need to output error and again re-enter new number until all 10 integer numbers will be inserted. Everything works in case if I say that these 10 numbers can't be 0 (I

Android: Layout object with integer in ID cannot be referenced

孤者浪人 提交于 2019-12-23 18:27:19
问题 I'm trying to set the images of some ImageButtons in my layout programmatically. To do so, I named my ImageButtons ic_1 to ic_5. During my initialization method, I want to loop through these 5 ImageButtons and set their images according to a list of possible icons. Basically users can change the order in which the icons should be shown, which in turn would change the image on the ImageButtons. However, i can't seem to reference the buttons since they have an Integer in their ID. The code I

What's causing Java (hailstone sequence) to crash in my program

家住魔仙堡 提交于 2019-12-23 17:19:23
问题 I´ve made a program that does the (usually called) hailstone sequence, The program basically does this: creates an int (value) and assign it a value. If the int is even, divide it by two. If the int is odd, multiply it by three and add one. Continue this process until n is equal to one. it seems to be working fine with most numbers, but this number 99888769, the app hangs on a negative integer. Why is this?, they say that no-one has yet been able to proove that it stops, I´m not expecting I

Grouping integers by set membership in Python

☆樱花仙子☆ 提交于 2019-12-23 16:14:12
问题 Working in Python, given a list of N sets of integers from the range range(s,n), how can I build a list that groups all these integers according to their set memberships? An example is really going to help me explain here: Example input (N=2 sets): integerRange = range(0,13) input = [set([0,1,2,3,7,8,9,12]), set([0,1,2,3,4,5,6,12])] Desired output: out = [set([10,11]), set([4,5,6]), set([7,8,9]), set([0,1,2,3,12])] So in the output each integer in range(s,n) appears exactly once, and there