JIYIK CN >

Current Location:Home > Learning > PROGRAM > Java >

>> operator in Java

Author:JIYIK Last Updated:2025/04/14 Views:

>>This guide will introduce you to the operator in Java . To understand this concept, you need to be familiar with some lower-level computing concepts. For example, bits, bytes, etc. Let's take a deeper look.


>>Operators in Java

In Java, >>the operator is the right shift operator. It shifts the given bit pattern to the right. For example, if you are familiar with bits, you know that the shifter shifts the bit pattern.

Take a look at the following example.

Let
X=0110101;
X>>1
Shift the bytes by 1, and the result will be
0110101
0011010   

Let
Y = 00111011
So when you do, x >> 2, 
result in x = 00001110

If you look at this example, you will notice a shift of one bit. After the shift, the value 0110101of changes to 0011010.

>>The operator works the same way in Java. We will see how it works and how you can write code for this purpose. Take a look.

public static void main(String[] args) {
  byte val = 100;
  // binary of 100 is 1100100
  val = (byte) (val >> 2); // shifting by two bits
  System.out.println(val);
  // after running the above code, the bits in binary will shift and it will look
  // like this, 0011001 which is equal to number 25 in decimals.
}

The above code is self-explanatory. We give a byte value 100. The machine will work in binary numbers and will 100read as 1100100.

Output:

25

After shifting it right two places, it will look like , which is equal to decimal 25. This is what the operator does 0011001in Java .>>

Previous: None

Next: None

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

如何在 Java 中延迟几秒钟的时间

Publish Date:2023/12/17 Views:223 Category:Java

本篇文章主要介绍如何在 Java 中制造程序延迟。本教程介绍了如何在 Java 中制造程序延时,并列举了一些示例代码来了解它。

如何在 Java 中把 Hashmap 转换为 JSON 对象

Publish Date:2023/12/17 Views:190 Category:Java

它描述了允许我们将哈希图转换为简单的 JSON 对象的方法。本文介绍了在 Java 中把 Hashmap 转换为 JSON 对象的方法。我们将看到关于创建一个 hashmap,然后将其转换为 JSON 对象的详细例子。

如何在 Java 中按值排序 Map

Publish Date:2023/12/17 Views:172 Category:Java

本文介绍了如何在 Java 中按值对 Map 进行排序。本教程介绍了如何在 Java 中按值对 Map 进行排序,并列出了一些示例代码来理解它。

如何在 Java 中打印 HashMap

Publish Date:2023/12/17 Views:198 Category:Java

本帖介绍了如何在 Java 中打印 HashMap。本教程介绍了如何在 Java 中打印 HashMap 元素,还列举了一些示例代码来理解这个主题。

在 Java 中更新 Hashmap 的值

Publish Date:2023/12/17 Views:152 Category:Java

本文介绍了如何在 Java 中更新 HashMap 中的一个值。本文介绍了如何在 Java 中使用 HashMap 类中包含的两个方法-put() 和 replace() 更新 HashMap 中的值。

Java 中的 hashmap 和 map 之间的区别

Publish Date:2023/12/17 Views:84 Category:Java

本文介绍了 Java 中的 hashmap 和 map 接口之间的区别。本教程介绍了 Java 中 Map 和 HashMap 之间的主要区别。在 Java 中,Map 是用于以键值对存储数据的接口,

在 Java 中获取用户主目录

Publish Date:2023/12/17 Views:224 Category:Java

这篇文章向你展示了如何在 Java 中获取用户主目录。本教程介绍了如何在 Java 中获取用户主目录,并列出了一些示例代码以指导你完成该主题。

Java 中 size 和 length 的区别

Publish Date:2023/12/17 Views:183 Category:Java

这篇文章教你如何知道 Java 中大小和长度之间的区别。本教程介绍了 Java 中大小和长度之间的区别。我们还列出了一些示例代码以帮助你理解该主题。

Java 中的互斥锁

Publish Date:2023/12/17 Views:119 Category:Java

了解有关 Java 中互斥锁的一切,在计算机科学领域,互斥或互斥被称为并发控制的属性。每台计算机都使用称为线程的最小程序指令序列。有一次,计算机在一个线程上工作。为了更好地理解,

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial