java中的位移操作 << >> >>>

本文详细介绍了Java中的三种位移操作:左移、带符号右移和无符号右移,并通过示例展示了它们的具体用法及特点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在java中,有三种位移操作运算符

左移 <<

带符号右移>>

无符号右移动>>>


1  左移

public static void main(String args[]){
    int a = 1;
    int b = -1;
    System.out.println(Integer.toBinaryString(a));
    System.out.println(Integer.toBinaryString(a<<1));
    System.out.println("--------------");
    System.out.println(Integer.toBinaryString(b));
    System.out.println(Integer.toBinaryString(b<<1));
}
1
10
--------------
11111111111111111111111111111111
11111111111111111111111111111110

左移的规则比较简单,在低位补零就可以了

2 右移
public static void main(String args[]){
    int a = 1;
    int b = -1;
    System.out.println(Integer.toBinaryString(a));
    System.out.println(Integer.toBinaryString(a>>1));
    System.out.println("--------------");
    System.out.println(Integer.toBinaryString(b));
    System.out.println(Integer.toBinaryString(b>>1));
}
1
0
--------------
11111111111111111111111111111111
11111111111111111111111111111111
右移的规则区分了正负
若符号为正,则在高位补0
若符号为负,则在高位补1
3 无符号右移

上面第二部分的>>实际上是一种有符号的右移动,
如果想要实现无符号的位移,可以使用>>>
这样不论符号正负,高位一律补0。
public static void main(String args[]){
    int a = 1;
    int b = -1;
    System.out.println(Integer.toBinaryString(a));
    System.out.println(Integer.toBinaryString(a>>>1));
    System.out.println("--------------");
    System.out.println(Integer.toBinaryString(b));
    System.out.println(Integer.toBinaryString(b>>>1));
}


1

0

--------------

11111111111111111111111111111111

1111111111111111111111111111111        //这里高位补零了,所以缺一位





<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %> <!DOCTYPE html> <html> <head> <title>员工信息查询</title> <style> body { font-family: 'Arial', sans-serif; background-color: #f4f8fb; color: #333; text-align: center; margin: 0; padding: 0; } h2 { margin-top: 20px; color: #4CAF50; animation: fadeIn 2s ease forwards; } table { margin: 20px auto; border-collapse: collapse; width: 80%; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); background-color: #ffffff; border-radius: 8px; } th, td { padding: 12px; border: 1px solid #ddd; text-align: center; } th { background-color: #4CAF50; color: white; } tr:hover { background-color: #e7f3fe; } .btn { margin-top: 20px; } a.button { display: inline-block; padding: 10px 20px; background-color: #4CAF50; color: white; text-decoration: none; border-radius: 5px; transition: background-color 0.3s ease; } a.button:hover { background-color: #45a049; } @keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } } </style> <script> // 页面加载时的淡入效果 window.onload = function() { document.body.style.opacity = 0; setTimeout(function() { document.body.style.transition = "opacity 1s ease"; document.body.style.opacity = 1; }, 100); }; </script> </head> <body> <h2>员工信息查询</h2> <table border="1"> <tr> <th>员工ID</th> <th>姓名</th> <th>性别</th> <th>职位</th> <th>联系方式</th> </tr> <tr> <td>${employee.id}</td> <td>${employee.name}</td> <td>${employee.gender}</td> <td>${employee.position}</td> <td>${employee.contact}</td> </tr> </table> <div class="btn"> <a href="${pageContext.request.contextPath}/employeemanagement" class="button">返回管理页面</a> </div> </body> </html>我想为这段代码的页面加载效果设计出别具风格的效果,在页面加载时整个表单将做波浪运动,表单的两段会先弯曲,然后表单的两段将以波浪的形式由慢到快向中间进行靠拢碰撞,在碰撞的瞬间整个表单压缩为一条彩色的竖状彩色直线,然后展开回复到表单原状
最新发布
06-18
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值