Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static String getPermission(int permission) { StringBuilder permissionStr = new StringBuilder(); String binaryString = Integer.toBinaryString(permission); binaryString = String.format("%16s", binaryString).replace(' ', '0'); int len = binaryString.length(); //PERMISSION_READ (0x00000001) if (binaryString.charAt(len - 1) == '1') { permissionStr.append("READ,"); } //PERMISSION_READ_ENCRYPTED (0x00000002) if (binaryString.charAt(len - 2) == '1') { permissionStr.append("READ_ENCRYPTED,"); } //PERMISSION_READ_ENCRYPTED_MITM (0x00000004) if (binaryString.charAt(len - 3) == '1') { permissionStr.append("READ_ENCRYPTED_MITM,"); } //PERMISSION_WRITE (0x00000010) if (binaryString.charAt(len - 5) == '1') { permissionStr.append("WRITE,"); } //PERMISSION_WRITE_ENCRYPTED (0x00000020) if (binaryString.charAt(len - 6) == '1') { permissionStr.append("WRITE_ENCRYPTED,"); } //PERMISSION_WRITE_ENCRYPTED_MITM (0x00000040) if (binaryString.charAt(len - 7) == '1') { permissionStr.append("WRITE_ENCRYPTED_MITM,"); } //PERMISSION_WRITE_SIGNED (0x00000080) if (binaryString.charAt(len - 8) == '1') { permissionStr.append("WRITE_ENCRYPTED_MITM,"); } //PERMISSION_WRITE_SIGNED_MITM (0x00000100) if (binaryString.charAt(len - 9) == '1') { permissionStr.append("WRITE_SIGNED_MITM,"); } String perStr = permissionStr.toString(); if (perStr.endsWith(",")) { perStr = perStr.substring(0, perStr.length() - 1); } return perStr; } }