packagecom.wangjun.test;importjava.util.ArrayList;importjava.util.HashSet;importjava.util.List;importjava.util.Random;importjava.util.Set;publicclassBitmap {publicstaticvoidmain(String[] args) {List<Integer> list =getList();System.out.println(list);int s =0;for (int i : list) {// 把1左移i位的值等于2的i次方// 之后把该值与s并上等于把该值上所有的1都插入s的对应位置上 s = s |1<< i; }StringBuilder sb =newStringBuilder(Integer.toBinaryString(s));System.out.println(sb.reverse()); // 对二进制做反转操作以方便观察 } /** * 生成随机的list */privatestaticList<Integer> getList() {Set<Integer> set =newHashSet<>();while (set.size() <15) {int i =newRandom().nextInt();if (i <0) i =-i; i = i %30;set.add(i); }List<Integer> list =newArrayList<>();list.addAll(set);return list; }}