Java Bitwise“&”整数

时间:2018-04-07 06:13:49

标签: java bitwise-operators bitwise-and

我有以下内容:

Session.setCacheMode(CacheMode)

我想要以下输出:

SELECT s.student_id as 'Student_Number', CONCAT(IFNULL(s.student_fname,''),' ', 
          IFNULL(s.student_mname,''),' ', IFNULL(s.student_lname,'')) 'Student_Name',s.student_program as 'Program', 
          (SUM(IF(stat.status_description='Late',1,0))) 'Total_Lates',
          (SUM(IF(stat.status_description='Absent',1,0))) 'Total_Absences', 
          Floor((SUM(IF(stat.status_description='Late',1,0))) / 3 + (SUM(IF(stat.status_description='Absent',1,0)))) 'Total_Absence_with_Lates' 
FROM attendance_tbl a 
LEFT JOIN student_tbl s ON s.student_id=a.entity_id 
LEFT JOIN status_tbl stat ON stat.status_id=a.status_id 
left join announcement_tbl ann on ann.announcement_date=a.date 
where a.course_id='SS019' and a.entity_type='Student' 
   and CONCAT(IFNULL(s.student_fname,''),' ', IFNULL(s.student_mname,''),' ', IFNULL(s.student_lname,'')) 
   and a.date!=ann.announcement_date and ann.announcement_description!='holiday' 
GROUP BY a.entity_id, CONCAT(IFNULL(s.student_fname,''),' ', IFNULL(s.student_mname,''),' ', IFNULL(s.student_lname,'')) 
order by Student_Name ASC

但我的问题是java在使用“&”之前转换为二进制文件操作,我真的希望能够以上述方式在整数上使用它。可以这样做吗?

1 个答案:

答案 0 :(得分:6)

首先,您需要使用a编写b0b文字,以表明它们是二进制文件。其次,您需要使用类似Integer.toBinaryString(int)的内容来获取按位&的二进制结果。像,

int a = 0b10001000, b = 0b10000000;
System.out.printf("(a&b) = %s;%n", Integer.toBinaryString(a & b));

输出(根据要求)

(a&b) = 10000000;