集册 Java实例教程 循环左移

循环左移

欢马劈雪     最近更新时间:2020-01-02 10:19:05

507
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
循环左移
//时 代 J a v a 公 众 号 - nowjava.com 提供


//package com.nowjava;


public class Main {

    public static void main(String[] argv) throws Exception {

        byte b = 2;

        int count = 2;

        System.out.println(circularBitShiftLeft(b, count));

    }


    public static byte circularBitShiftLeft(byte b, int count) {

        if (count < 0)

            count = count * -1;

            /**
            时 代 J a v a - N o w J a v a . c o m 提供 
            **/

        if (count > 7)

            count = count % 8;


        if (count == 0)

            return b;


        if (b >= 0)

            return (byte) ((b << count) | (b >>> Byte.SIZE - count));

        else {

            
展开阅读全文