long-integer

Copy 6 byte array to long long integer variable

独自空忆成欢 提交于 2019-12-13 09:14:37
问题 I have read from memory a 6 byte unsigned char array. The endianess is Big Endian here. Now I want to assign the value that is stored in the array to an integer variable. I assume this has to be long long since it must contain up to 6 bytes. At the moment I am assigning it this way: unsigned char aFoo[6]; long long nBar; // read values to aFoo[]... // aFoo[0]: 0x00 // aFoo[1]: 0x00 // aFoo[2]: 0x00 // aFoo[3]: 0x00 // aFoo[4]: 0x26 // aFoo[5]: 0x8e nBar = (aFoo[0] << 64) + (aFoo[1] << 32) +

Convert hex- bin- or decimal string to long long in C++

痞子三分冷 提交于 2019-12-13 07:46:49
问题 I have this code which handles Strings like "19485" or "10011010" or "AF294EC"... long long toDecimalFromString(string value, Format format){ long long dec = 0; for (int i = value.size() - 1; i >= 0; i--) { char ch = value.at(i); int val = int(ch); if (ch >= '0' && ch <= '9') { val = val - 48; } else { val = val - 55; } dec = dec + val * (long long)(pow((int) format, (value.size() - 1) - i)); } return dec; } this code works for all values which are not in 2's complement. If I pass a hex

UINT_MAX the same as ULONG_MAX in C

对着背影说爱祢 提交于 2019-12-13 05:45:32
问题 While solving exercises from the K&R C book, I stumbled upon the exercise 2.1. At first I got as UINT_MAX as -1 , but then I used the %u placeholder, but now its giving me the same number as ULONG_MAX . In the book in Appendix B, they say that UINT_MAX should be 65535 and ULONG_MAX should be 4294967295 , but when running the exercise, its giving me for both UINT_MAX and ULONG_MAX as 4294967295 . Why is that? 回答1: First of all, the right way to print an unsigned long is not %u but %lu . Second

error: no suitable method found for put(String,int)

99封情书 提交于 2019-12-13 04:34:40
问题 I got errors when compiling this: TreeMap <String, Long> myMap = new TreeMap <String, Long>(); //populate the map myMap.put("preload_buffer_size", 1024); myMap.put("net_buffer_length", 1024); //etc... error: no suitable method found for put(String,int) myMap.put("preload_buffer_size", 1024); ^ method TreeMap.put(String,Long) is not applicable (actual argument int cannot be converted to Long by method invocation conversion) method AbstractMap.put(String,Long) is not applicable (actual argument

Detecting if a string is a double or long in C

拜拜、爱过 提交于 2019-12-13 04:29:15
问题 I'm dealing with an char[] containing text which should represent a double number value OR a long number. I'm in a need to write a function that detects which of the above data-types is represented (if any). I thought about using strtol() and check if it fails to parse the entire string, and if it fails, using strtod(). I would be happy to see whether there is a better option to do so. Thanks. 回答1: I thought about using strtol() and check if it fails to parse the entire string, and if it

Converting from unsigned long int to signed int and vice versa

不打扰是莪最后的温柔 提交于 2019-12-13 04:04:21
问题 I would like to pass a signed int to gsl_rng_uniform_int (const gsl_rng * r, unsigned long int n) . The signed int that I'm passing is greater than or equal to zero. The function will return a number between 0 and n , so if I pass it a positive signed int, it will return something that is in the range of a signed int. I then want to store the return value in a signed int. What's the cleanest way to do this with the obvious expected behaviour? I'm on a 64-bit compiler on a 64-bit Linux machine

How can I extract the value of this json in php?

£可爱£侵袭症+ 提交于 2019-12-13 03:59:50
问题 I would like to know, how take the value "Tile32px" from this Json: (http://360api.chary.us/?gamertag=superdeder) with PHP. I tried this way: <?php $json = file_get_contents('http://360api.chary.us/?gamertag=superdeder'); $gamer = json_decode($json); echo $gamer->Gamertag; echo "<br><br>"; $data = json_decode($json, true); $users=$data['LastPlayed']; foreach ($users as $user) { echo $user['Title']; echo "<br>"; } echo "<br>"; $users2=$data['Pictures']; foreach ($users2 as $user2) { echo

Android String variable (HH:mm) to long variable miliseconds

时光毁灭记忆、已成空白 提交于 2019-12-13 02:30:40
问题 I have a String variable in this format "HH:mm" . Lets say the variable value is 05:30. How would I be able to get those numbers from string and calculate : (05 * 60 * 60 * 1000) + (30 * 60 * 1000) and put that number (miliseconds) in a new long variable. Basically I need to convert the String time variable into miliseconds long variable. 回答1: Let s contain the string of interest. Then e.g. you can say String s = "5:30"; Pattern p = Pattern.compile("(\\d+):(\\d+)"); Matcher m = p.matcher(s);

second to nanosecond - struct itimerspec

怎甘沉沦 提交于 2019-12-13 02:15:28
问题 i am populating the timespec structure. The intention is, user will always enter values in seconds (can also be 0.01 secs), so we are converting the seconds to nanoseconds using: lt_leak_start = atoll(getenv("LT_LEAK_START")) * sec_to_nsec; where variable static long sec_to_nsec = 1000000000; and then using it as an argument to settime: timer_settime(timerid,0,&its,NULL) . But on doing it an error occurs: settimer failed: Invalid argument Please help me. Thanks in advance. enter code here

Android: Scrollbar Accelerator?

假如想象 提交于 2019-12-13 01:24:38
问题 I'm writing an Android application that contains lots of long lists and I need to accelerate scrolling somehow. The Android Contacts application for example uses a list of letters to allow quick scrolling to a certain spot in the list ... it's not exactly what I'm looking for though. I've seen other applications use a handle (or paddle) that appears when you start scrolling and allows you to easily drag the scrollbars to a specific location, that might be a better solution for me. I'm