Integer vs int: with regard to memory

In general, the heap memory used by a Java object in Hotspot consists of: an object header, consisting of a few bytes of “housekeeping” information; memory for primitive fields, according to their size (int n->32 bits) memory for reference fields (4 bytes each) (Integer n ->32 bits) padding: potentially a few “wasted” unused bytes after … Read more

How to round to nearest even integer?

Try this (let’s use Math.Round with MidpointRounding.AwayFromZero in order to obtain “next even value” but scaled – 2 factor): double source = 1123.0; // 1124.0 double result = Math.Round(source / 2, MidpointRounding.AwayFromZero) * 2; Demo: double[] tests = new double[] { 1.0, 1123.1, 1123.0, 1122.9, 1122.1, 1122.0, 1121.5, 1121.0, }; string report = string.Join(Environment.NewLine, tests … Read more

Parsing a Hexadecimal String to an Integer throws a NumberFormatException?

Will this help? Integer.parseInt(“00ff00”, 16) 16 means that you should interpret the string as 16-based (hexadecimal). By using 2 you can parse binary number, 8 stands for octal. 10 is default and parses decimal numbers. In your case Integer.parseInt(primary.getFullHex(), 16) won’t work due to 0x prefix prepended by getFullHex() – get rid of and you’ll … Read more

Convert INT to DATETIME (SQL)

you need to convert to char first because converting to int adds those days to 1900-01-01 select CONVERT (datetime,convert(char(8),rnwl_efctv_dt )) here are some examples select CONVERT (datetime,5) 1900-01-06 00:00:00.000 select CONVERT (datetime,20100101) blows up, because you can’t add 20100101 days to 1900-01-01..you go above the limit convert to char first declare @i int select @i … Read more

If the size of “long” and “int” are the same on a platform – are “long” and “int” different in any way?

They are not compatible types, which you can see with a a simple example: int* iptr; long* lptr = iptr; // compiler error here So it mostly matters when dealing with pointers to these types. Similarly, there is the “strict aliasing rule” which makes this code undefined behavior: int i; long* lptr = (long*)&i; *lptr … Read more