navrsalemile
Programmer
Hi all,
I have three boolean variables:
boolean flag1;
boolean flag2;
boolean flag3;
I want to represent them as octal number and convert this octal number into integer represented as String, i.e. if flags are:
flag1 is true
flag2 is false
flag3 is true
then String should be "5" which is binary 5 (0b101).
I came up with:
String suffix = Integer.toString((int)(flag1 ? 1 : 0) << 2 | (int)(flag2 ? 1 : 0) << 1 | (int)(flag3 ? 1 : 0));
but wonder if there is shorter more elegant solution?
many thanks,
mile
I have three boolean variables:
boolean flag1;
boolean flag2;
boolean flag3;
I want to represent them as octal number and convert this octal number into integer represented as String, i.e. if flags are:
flag1 is true
flag2 is false
flag3 is true
then String should be "5" which is binary 5 (0b101).
I came up with:
String suffix = Integer.toString((int)(flag1 ? 1 : 0) << 2 | (int)(flag2 ? 1 : 0) << 1 | (int)(flag3 ? 1 : 0));
but wonder if there is shorter more elegant solution?
many thanks,
mile