Converting a long to a boolean array in Java and Converting a boolean array to a long in java

 

code screen

Converting a long to a boolean array in Java

 

	  private static boolean[] msExchELCMailboxFlags(long value) {
		 
		  char[] cArray = new char[7];
		  Arrays.fill(cArray, '0');
		  if(value != -1) {
			  char[] chars = Long.toBinaryString(value).toCharArray();
			  
	            int offset = 0;
	            if (chars.length < cArray.length) {
	            	offset = cArray.length - chars.length;
	            }
	            
	            System.arraycopy(chars, 0, cArray, offset, chars.length);

		  }
		  boolean[] bits = new boolean[cArray.length];
          for(int i = 0; i < cArray.length; i++) {
        	  bits[i] = cArray[i] == '1';
          }
		  return bits;
	  }

 

 

Converting a boolean array to a long in java

 

 

	  private static long msExchELCMailboxFlags( boolean[] attributes ){
		  char[] chars = new char[7];
		  Arrays.fill(chars, '0');
		  if(attributes != null){
			  for (int i = 0; i < attributes.length; ++i) {
				   if(attributes[i]) 
					   chars[i] = '1';
			  }
		  }
		  return new BigInteger(new String(chars),2).longValue();
	  }