---
title: "char,byte,short位移运算时注意事项"
author: "only_java"
date: "2009-10-23T11:25:11Z"
tags: []
slug: "char-byte-short"
draft: false
lastmod: "2009-10-23T11:25:30Z"
id: 502161
url: "https://only-java.iteye.com/blog/502161"
---

对char，byte或者short进行移位处理，那么在移位进行之前，它们会自动转换成一个int。只有右侧的5个低位才会有用。这样可防止我们在一个int数里移动不切实际的位数。若对一个long值进行处理，最后得到的结果也是long。此时只会用到右侧的6个低位，防止移动超过long值里现成的位数。

 

 

对char，byte或者short进行移位处理，那么在移位进行之前，它们会自动转换成一个int。

比如 byte bt=128;则在进行位移运算前首先会把bt转换为int类型，即刚开始时：01000000,如果要进行bt&lt;&lt;8运算时，则首先bt会转换为2进制 00000000000000000000000010000000

然后向左移动8位。        结果为 00000000000000001000000000000000值为32768