@@ -324,6 +324,40 @@ Joda Date api
324324 2022-04-27T16:53:23.903014+05:30[Asia/Calcutta]
325325 Wed Apr 27 16:53:23 IST 2022
326326
327-
328-
329-
327+
328+
329+
330+
331+
332+ ##java Data Type deep concept
333+ ----------------------------------------------
334+ java contain 8 data type(primitives)
335+ 6 type number - 6(byte-1Byte,short-2Byte,int-4Byte,long-8Byte,float-4Byte,double-8Byte)
336+ 1 type for boolean (boolean-1bit) [0,1]
337+ 1 type for character(char-2byte) --only positive num[0-(2^16-1)] = [0 to 65535]
338+ for byte -contains both negative & positive -- so in 1 byte = 8 bits
339+ total possible number using 8 bit = 2^8 = 256 means half number should be negative and half number should be positive
340+ first negative number; 256/2 = -128
341+ last postive number = 256 -(128+1) = 127
342+ so validate range [-128,127]
343+ formula = total possible = (last-first+1) = 256 = 127-(-128)+1=256
344+ 1 added because zero belongs to positive number
345+ note: always java store negative num inform of 2's complement.
346+
347+ //2s complement rules => reverse all bit from left to right plus
348+ change all zero to 1 from left to right till 1st one
349+ example:
350+ num =-5 = binary for 5 = 00000101
351+ apply 2s complement rules = 11111011 (java store for -5)
352+
353+
354+
355+ */
356+ public static void main(String[] args) {
357+ byte num = -5; // binary 1 = 00000001 =>1s complement = 11111110 =2's compl =11111110
358+ String s = Integer.toBinaryString(num);
359+ System.out.println(s.substring(24));
360+
361+ }
362+
363+
0 commit comments