Skip to content

Instantly share code, notes, and snippets.

@adityasatrio
Last active August 29, 2015 14:07
Show Gist options
  • Save adityasatrio/9e327f19d75342efdea4 to your computer and use it in GitHub Desktop.
Save adityasatrio/9e327f19d75342efdea4 to your computer and use it in GitHub Desktop.
Simple Bitwise Role
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class SimpleBitwiseEdit
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int read = 1;
int add = 2;
int edit = 4;
int submit = 8;
int roleA = (read);
int roleB = (read | add);
int roleC = (read | edit);
int roleD = (read | edit | add);
System.out.println("roleA = "+roleA);
System.out.println("roleB = "+roleB);
System.out.println("roleC = "+roleC);
System.out.println("roleD = "+roleD);
System.out.println("\n test role bitwise");
int test = (roleC & edit);
System.out.println("test = "+test);
}
}
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class SimpleBitwiseRole
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
int read = 1;
int add = 2;
int edit = 4;
int submit = 8;
int roleA = (read);
int roleB = (roleA | add); //read add
int roleC = (roleB | edit) ; //read add edit
int roleD = (roleC & (~edit)); //read add
int roleF = (roleC & (~add)); //read edit
System.out.println("roleA = "+roleA);
System.out.println("roleB = "+roleB);
System.out.println("roleC = "+roleC);
System.out.println("roleD = "+roleD);
System.out.println("roleF = "+roleF);
System.out.println("test role bitwise");
int test = (roleF & add);
System.out.println("test = "+test);
}
}
@adityasatrio
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment