提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
将位设置为字节值
//package com.nowjava; /** 来 自 时 代 J a v a - nowjava.com **/ public class Main { public static void main(String[] argv) throws Exception { byte b = 2; int pos = 2; System.out.println(setBit(b, pos)); } /** * * @param b * @param pos * @return */ public static byte setBit(byte b, int pos) { return (byte) (b | (1 << pos)); } }