I'm pretty new to java and I am trying to to convert this string array with hexadecimal values into an int array. I have no clue how to do it.   import java.io.*; import java.util.*;  public class cruzD_OSpgm2 {      public static void fileReader()     {         ArrayList&lt;String&gt; ramChipList = new ArrayList&lt;String&gt;();         try          {            BufferedReader br = new BufferedReader(new                 FileReader("RAMerrors"));            String sCurrentLine;            while ((sCurrentLine = br.readLine()) !=null)            {                ramChipList.add(sCurrentLine);            }         }         catch (IOException e)         {             e.printStackTrace();         }             String[] ramChip = new String[ramChipList.size()];         ramChip = ramChipList.toArray(ramChip);     }      public static void main(String[] args)     {         fileReader();     } }   here are the 4 hex values  ABCDEFABC 1A00D0000 7A0EDF301 3CDAEFFAD
2136
I am looking for a way to convert a long string (from a dump), that represents hex values into a byte array.  I couldn't have phrased it better than the person that posted .  But to keep it original, I'll phrase it my own way: suppose I have a string "00A0BF" that I would like interpreted as the  byte[] {0x00,0xA0,0xBf}   what should I do?  I am a Java novice and ended up using BigInteger and watching out for leading hex zeros. But I think it is ugly and I am sure I am missing something simple.
110
Can we convert a hex string to a byte array using a built-in function in C# or do I have to make a custom method for this?
20332
i just made a test, to see how much data i can put in a string before i reach the the heapsize limit and i get an unexpected behaviour   string  csvFile = '"XXXXXXX","XXPX XXRXXXX","XXPX BP","XLXXXXR","XXXXVXXX PRXXXDXXXX","XXPX XXXXVXXX","XDRXXXDXX LXGXLX","XXXXRX XXLX","LXXXX XX","DXXX XXXZXX XXXXVXXX","DXXX XXXX XXXXVXXX","XXDXXX BP","XXDXXX XXXXXLX","PXRXXXX XVX","DXXXXXXXZXXXX","XXXX XXRXXXXRX","XXGXXXX XXRXXXXRX","DXXX DX XXXXXXX","LXXGX DX XXXXXXX","PXD","XXXXX XXXXRXXXXXLX","XXXX RXXXPXXX","XXDXRXZZX RXXXPXXX","PRXVXXXXX RXXXPXXX","XXXXXX RXXXPXXX","XXP RXXXPXXX","XXXXRX XXLXXXXX 1","XXXXRX XXLXXXXX 2","XXXXRX XXX","XXDXRXZZX XXXXL","XXDXRXZZX XXRXXXXRX","XXXXXX XXRXXXXRX","PRXVXXXXX XXRXXXXRX","XXP XXRXXXXRX","XXXXX XLXXXXX","XXDXXX PRXXXXX","DXXX XXXXXZXXXX","XXPX DXXXXXXXX","XHXXVX XXXXXRX","DXXX XXXXXXXXX XXXXXRX","DXXX XXXDXXZX XXXXXRX","XXPXRXX XXXXLX","XXPXRXX RXXXDXX XXXXDXXX","PRXXXXXXXXXXXXXXZXXXX PRXXXXXXXXXX","DXXX PRXXXXXXXXXXXXXXZXXXX PRXXXXXXXXXX"';  string  csvFile2='',csvFile3; system.debug(limits.getLimitHeapSize()); system.debug(limits.getHeapSize()); for(integer i=0;i&lt;3618;i++){ csvFile2+='\n'+csvFile; }   system.debug(1.0*limits.getHeapSize()); system.debug((1.0*limits.getHeapSize())/limits.getLimitHeapSize()*100);   with 3618 iteraction i get    Heap size 3001245.0 Which correspond to ~50% of the heap size limit in the Synchronous context   but if i go to 3619 iteractions in the for, i get the error "Apex heap size too large: 6001368".... which surprise me a lot...   I'm not getting out why this behaviour is occurring. Do you have any similar experience? There is a reason for this?  Seems more about limits on strings, in effect the string csvFile2 overcome 3M characters... but i dont know
28473
How do I get the  value of a character as an int in ?
106280
Object o = new Long[0] System.out.println( o.getClass().isArray() ) System.out.println( o.getClass().getName() ) Class ofArray = ???   Running the first 3 lines emits;  true [Ljava.lang.Long;   How do I get ??? to be type long?   I could parse the string and do a Class.forname(), but thats grotty.   What's the easy way?
102402
I'm wanting to parse a string into a nullable int in C#.  ie. I want to get back either the int value of the string or null if it can't be parsed.  I was kind of hoping that this would work  int? val = stringVal as int?;   But that won't work, so the way I'm doing it now is I've written this extension method  public static int? ParseNullableInt(this string value) {     if (value == null || value.Trim() == string.Empty)     {         return null;     }     else     {         try         {             return int.Parse(value);         }         catch         {             return null;         }     } }      Is there a better way of doing this?  EDIT:  Thanks for the TryParse suggestions, I did know about that, but it worked out about the same.  I'm more interested in knowing if there is a built-in framework method that will parse directly into a nullable int?
26106
I have webservice which is passed an array of ints. I'd like to do the select statement as follows but keep getting errors. Do I need to change the array to a string?  [WebMethod] public MiniEvent[] getAdminEvents(int buildingID, DateTime startDate) {         command.CommandText = @"SELECT id,                             startDateTime, endDateTime From                             tb_bookings WHERE buildingID IN                             (@buildingIDs) AND startDateTime &lt;=                             @fromDate";      SqlParameter buildID = new SqlParameter("@buildingIDs", buildingIDs); }
4461
This prints 83  System.out.println(0123)   However this prints 123  System.out.println(123)   Why does it work that way?
6195
Using PHP, what's the fastest way to convert a string like this: "123" to an integer?  Why is that particular method the fastest? What happens if it gets unexpected input, such as "hello" or an array?
35663
My controller code is as follows -          for(String resStr : responseArray){             if(resStr.indexOf('r_error_str') != -1){                 responseString += resStr.substring(resStr.indexOf('=') + 1);                  responseString += '\n';             }         }   but when i display this 'responseString ' String using 'apex:outputLabel or apex:outputText or as Exception message '\n' is not converting in new line. Whole String is coming in one line.  Can anyone explain why is this happining
89192
I have some HTML I am trying to parse.  There are cases where the html attributes alone are not going to help me identify the row type (header versus data).  Fortunately, if my row is a data row then it should have some values that can be converted to integers.  I have figured out how to convert the unicode to an integer for those cases that it is possible to make the conversion.  I am struggling to write the logic to move past the cells that the conversion will not work because the cell has content that must be treated as text.  for example if rowColumn[1][3] can be converted to an integer I can do so by   int(rowColumn[1][3].replace(',','').strip('$'))   but I get an error if rowColumn[1][3] has text content.
23909
Looking for reviewers to suggest optimization and improvements, and to evaluate coding practices.  final class Variables {     private final int x;     private final int y;      Variables(int x2, int y2) {         this.x = x2;         this.y = y2;     }      public int getX() {         return x;     }      public int getY() {         return y;     }      @Override public String toString()  {          return "x = " + x + " y = " + y;     } }  public final class FindMissing {      private FindMissing() {};      /**  * Takes an input a sorted array with two variables that repeat in the  * range. Remaining variable are consecutive. and returns two variables that repeats  *   * eg: for a range of 1,2,3,4, a valid input is [1, 4], [1, 3] etc.  *   * @param a : the sorted array.  */ /*  * Why is start needed ?  * If start is not given then if a1 is empty how do we know if missing numbers were  * [1, 2] or [4, 5] ??.   */ public static Variables sortedConsecutiveTwoMissing (int[] a, int startOfRange) {     if (a == null) throw new NullPointerException("a1 cannot be null. ");      int low = startOfRange;     // calculating the highest value of the range. it needs to be 2 more than length since all elememts are consecutive.     int high = startOfRange + (a.length - 1) + 2;      int i = 0;     boolean foundX = false;     int x = 0;       while (i &lt; a.length) {         if (a[i] != low) {             if (foundX) {                 return new Variables(x, low);             } else {                 x = low;                 foundX = true;             }         } else {             i++;         }         low++;     }      return new Variables(x, high);  }  public static void main(String[] args) {         // unsortedConsecutiveTwoMissing         int[] a6 = {1, 4};         System.out.println("Expected 2 and 3, Actual " + sortedConsecutiveTwoMissing(a6, 1));         // unsortedConsecutiveTwoMissing         int[] a7 = {-4, -1};         System.out.println("Expected -3 and -2, Actual " + sortedConsecutiveTwoMissing(a7, -4));         int[] a8 = {-4, -3, -2, -1};         System.out.println("Expected 0 and 1, Actual " + sortedConsecutiveTwoMissing(a8, -4));         int[] a9 = {5};         System.out.println("Expected 4 and 6, Actual " + sortedConsecutiveTwoMissing(a9, 4));         }      }
20025
Possible Duplicate:          How do you convert a C++ string to an int?  Assume you are expecting the string to have actual numbers in it ("1", "345", "38944", for example).  Also, let's assume you don't have boost, and you really want to do it the C++ way, not the crufty old C way.
14414
I am trying to convert an integer number in C into an array containing each of that number's digits  i.e.  if I have   int number = 5400   how can I get to   int numberArray[4]   where   numberArray[0] = 0; numberArray[1] = 0; numberArray[2] = 4; numberArray[3] = 5;   Any suggestions gratefully received.
104482
What is the best way to convert an Int value to the corresponding Char in Utf16, given that the Int is in the range of valid values?
91805
Short prestory. Typical problem: you have a lot of small string and you want to concatenate them all in one big string. The code like for(Integer i = 0; i &lt; smallStringsSize; i++){     bigString += smallStrings[i]; }  will solve this problem, but it has to produce a lot of unnecessary string objects that consume your heap. That is why Java has classes like StringBuilder and StringBuffer that allow you to solve this problem wihtout consuming too many memory. Thus, I decided to try to do my own StringBuilder in apex. String class has two methods that looked suitable for it:   and  . Here is the code that i used to test these methods against &quot;+=&quot; concatenantion (ready to execute in anonymous): List&lt;String&gt; chars = new List&lt;String&gt;(); List&lt;Integer&gt; charsCode = new List&lt;Integer&gt;(); Integer size = 10000; String chartToAdd = 'Ω'; for(Integer i = 0; i &lt; size; i++){     chars.add(chartToAdd);     charsCode.add(String.valueOf(chartToAdd).charAt(0)); } String joinS = '', forS = '', fromS = ''; Integer initialHeapSize = Limits.getHeapSize(); Integer initialCPUtime = Limits.getCpuTime(); System.debug('initialHeapSize ' + initialHeapSize); System.debug('initialCPUtime ' + initialCPUtime); joinS = String.join(chars, ''); Integer joinHeapSize = Limits.getHeapSize() - initialHeapSize; Integer joinCPUtime = Limits.getCpuTime() - initialCPUtime; System.debug('-------- String.join ---------'); System.debug('joinHeapSize ' + joinHeapSize); System.debug('joinCPUtime ' + joinCPUtime); for(Integer i = 0; i &lt; size; i++){     forS += chars[i]; } Integer forHeapSize = Limits.getHeapSize() - joinHeapSize - initialHeapSize; Integer forCPUtime = Limits.getCpuTime() - joinCPUtime - initialCPUtime; System.debug('-------- for each += ---------'); System.debug('forHeapSize ' + forHeapSize); System.debug('forCPUtime ' + forCPUtime); fromS = String.fromCharArray(charsCode); Integer fromHeapSize = Limits.getHeapSize() - forHeapSize - joinHeapSize - initialHeapSize; Integer fromCPUtime = Limits.getCpuTime() - forCPUtime - joinCPUtime - initialCPUtime; System.debug('-------- String.fromCharArray ---------'); System.debug('fromHeapSize ' + fromHeapSize); System.debug('fromCPUtime ' + fromCPUtime); System.debug(''); System.debug('-------- strings ----------'); System.debug('joins ' + joins); System.debug('fors ' + fors); System.debug('fromS ' + fromS);  The result of this code execution:  initialHeapSize 161166 initialCPUtime 242 -------- String.join --------- joinHeapSize 10016 joinCPUtime 17 -------- for each += --------- forHeapSize 10024 forCPUtime 48 -------- String.fromCharArray --------- fromHeapSize 10016 fromCPUtime 5  As you can see, the heap size for each approach is so close to 10 kilobytes, what is a size of the string of 10 000 characters (size) if each character takes only one byte. In case of creating 10 000 additional string objects, the heap size would be a bit more than 50 megabytes (10 000 * (1 + 10 000)/2). Taking into consideration the above,  Does not the '+=' concatenation create any additional string objects that devour your heap? Did not I miss anything? I am so amazed.  As you see, I use Omega 'Ω' as a chartToAdd. It has  the high-surrogate code point equals to 937, that needs at least 2 bytes to be encoded. How can 10 000 Omegas consume only 10 000 bytes of the heap size?  What weightful reasons Salesforce has that they do not to add the character data type? Any ideas?
7244
How can I convert a string of bytes into an int in python?   Say like this: 'y\xcc\xa6\xbb'  I came up with a clever/stupid way of doing it:  sum(ord(c) &lt;&lt; (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))   I know there has to be something builtin or in the standard library that does this more simply...  This is different from  for which you can use int(xxx, 16), but instead I want to convert a string of actual byte values.  UPDATE:  I kind of like James' answer a little better because it doesn't require importing another module, but Greg's method is faster:  &gt;&gt;&gt; from timeit import Timer &gt;&gt;&gt; Timer('struct.unpack("&lt;L", "y\xcc\xa6\xbb")[0]', 'import struct').timeit() 0.36242198944091797 &gt;&gt;&gt; Timer("int('y\xcc\xa6\xbb'.encode('hex'), 16)").timeit() 1.1432669162750244   My hacky method:  &gt;&gt;&gt; Timer("sum(ord(c) &lt;&lt; (i * 8) for i, c in enumerate('y\xcc\xa6\xbb'[::-1]))").timeit() 2.8819329738616943   FURTHER UPDATE:  Someone asked in comments what's the problem with importing another module. Well, importing a module isn't necessarily cheap, take a look:  &gt;&gt;&gt; Timer("""import struct\nstruct.unpack("&gt;L", "y\xcc\xa6\xbb")[0]""").timeit() 0.98822188377380371   Including the cost of importing the module negates almost all of the advantage that this method has. I believe that this will only include the expense of importing it once for the entire benchmark run; look what happens when I force it to reload every time:  &gt;&gt;&gt; Timer("""reload(struct)\nstruct.unpack("&gt;L", "y\xcc\xa6\xbb")[0]""", 'import struct').timeit() 68.474128007888794   Needless to say, if you're doing a lot of executions of this method per one import than this becomes proportionally less of an issue. It's also probably i/o cost rather than cpu so it may depend on the capacity and load characteristics of the particular machine.