integer

Parsing integer strings in Java [duplicate]

↘锁芯ラ 提交于 2020-01-22 17:53:13
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: How to convert a hexadecimal string to long in java? I know that Java can't handle this: Integer.parseInt("0x64") Instead you have to do this: Integer.parseInt("64", 16) Is there something built into Java that can automatically parse integer strings for me using the standard prefixes for hex, octal, and lack of prefix for decimal (so that I don't have to strip off the prefix and explicitly set the base)? 回答1:

Cannot invoke toString() on the primitive type int

久未见 提交于 2020-01-22 13:54:06
问题 Basically, what I'm trying to do, is get the item ID, and set a price from a ini, basically like: itemid:price but, i cannot simply do item.getId().toString(). I'm trying to get item What can I do to make it a string? public static void getBuyPrice(Item item) { try { String itemId = item.getId().toString(); BufferedReader br = new BufferedReader(new FileReader(new File( "./data/prices.ini"))); String line; while ((line = br.readLine()) != null) { if (line.equals(itemId)) { String[] split =

Cannot invoke toString() on the primitive type int

假如想象 提交于 2020-01-22 13:53:49
问题 Basically, what I'm trying to do, is get the item ID, and set a price from a ini, basically like: itemid:price but, i cannot simply do item.getId().toString(). I'm trying to get item What can I do to make it a string? public static void getBuyPrice(Item item) { try { String itemId = item.getId().toString(); BufferedReader br = new BufferedReader(new FileReader(new File( "./data/prices.ini"))); String line; while ((line = br.readLine()) != null) { if (line.equals(itemId)) { String[] split =

What is the maximum integer value in Flex?

感情迁移 提交于 2020-01-21 11:19:07
问题 I was trying to display a number: 2893604342.00. But, when i am displaying it it is displayed as: -2893604342. Following is the code snippet ... avg += int(totalData[i][col.dataField]); I have even replaced it with Number , but it's still showing the same negative number. Please let me know whether there is any problem with int or Number ! 回答1: The maximum values are accessible through each numeric type's static properties: Number.MAX_VALUE uint.MAX_VALUE int.MAX_VALUE (Just trace 'em.) 回答2:

How to print a signed integer as hexadecimal number in two's complement with python?

假装没事ソ 提交于 2020-01-21 10:56:29
问题 I have a negative integer (4 bytes) of which I would like to have the hexadecimal form of its two's complement representation. >>> i = int("-312367") >>> "{0}".format(i) '-312367' >>> "{0:x}".format(i) '-4c42f' But I would like to see "FF..." 回答1: Here's a way (for 16 bit numbers): >>> x=-123 >>> hex(((abs(x) ^ 0xffff) + 1) & 0xffff) '0xff85' (Might not be the most elegant way, though) 回答2: >>> x = -123 >>> bits = 16 >>> hex((1 << bits) + x) '0xff85' >>> bits = 32 >>> hex((1 << bits) + x)

Append an int to char*

怎甘沉沦 提交于 2020-01-20 14:24:46
问题 How would you append an integer to a char* in c++? 回答1: First convert the int to a char* using sprintf() : char integer_string[32]; int integer = 1234; sprintf(integer_string, "%d", integer); Then to append it to your other char*, use strcat() : char other_string[64] = "Integer: "; // make sure you allocate enough space to append the other string strcat(other_string, integer_string); // other_string now contains "Integer: 1234" 回答2: You could also use stringstreams. char *theString = "Some

Append an int to char*

本秂侑毒 提交于 2020-01-20 14:22:11
问题 How would you append an integer to a char* in c++? 回答1: First convert the int to a char* using sprintf() : char integer_string[32]; int integer = 1234; sprintf(integer_string, "%d", integer); Then to append it to your other char*, use strcat() : char other_string[64] = "Integer: "; // make sure you allocate enough space to append the other string strcat(other_string, integer_string); // other_string now contains "Integer: 1234" 回答2: You could also use stringstreams. char *theString = "Some

Why do MP3 files use Synchsafe Integers?

六月ゝ 毕业季﹏ 提交于 2020-01-20 03:25:25
问题 I started reading mp3-files in c++. All went well until I read the specs of the ID3-Tag. There is some information in the ID3v2-Header about its size stored in so-called Synchsafe Integers. That is a four-byte integer where the most significant bit of each byte is set to zero. I found out how to convert it to an ordinary integer, but I cannot stop asking myself why an integer value is stored in such an unnecessarily complicated way. I hope there is someone who can tell me why it is stored

why is not (123 == 0123) in java?

浪尽此生 提交于 2020-01-19 05:38:07
问题 I am developing an application in Android using Eclipse. I wrote the following code and in tests the first and third " if " block is not reachable. Why? When I add a leading zero to a number, the equal operator returns false. int var = 123; if (var == 0123) { //not reachable } if (var == 123) { //reachable } if (var == (int)0123) { //not reachable } if (var == (int)123) { //reachable } 回答1: 0123 is an octal number (leading 0), while 123 is a decimal number. so 0123 actually equals to 83. 回答2:

Getting non-integer results in Data Explorer

[亡魂溺海] 提交于 2020-01-17 08:05:35
问题 The Stack Exchange Data Explorer allows SQL queries against a Stack Exchange database. The following query — select month(CreationDate) month, year(CreationDate) year, sum(case when lower(left(Title,2))='wh' then 1 else 0 end)/count(*) wh, (select sum(Score)/count(*) from Posts u where month(CreationDate)=month(t.CreationDate) and year(CreationDate)=year(t.CreationDate) and lower(left(Title,2))='wh' and PostTypeId=1 -- question ) wh_score, sum(Score)/count(*) score, (select sum(AnswerCount)