久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在Java中,我可以用二進制格式定義一個整數常量

In Java, can I define an integer constant in binary format?(在Java中,我可以用二進制格式定義一個整數常量嗎?)
本文介紹了在Java中,我可以用二進制格式定義一個整數常量嗎?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

類似于如何用十六進制或八進制定義整數常量,我可以用二進制來定義嗎?

Similar to how you can define an integer constant in hexadecimal or octal, can I do it in binary?

我承認這是一個非常簡單(而且很愚蠢)的問題.我的谷歌搜索結果是空的.

I admit this is a really easy (and stupid) question. My google searches are coming up empty.

推薦答案

因此,隨著 Java SE 7 的發布,二進制表示法成為開箱即用的標準.如果你對二進制有很好的理解,語法就非常簡單明了:

So, with the release of Java SE 7, binary notation comes standard out of the box. The syntax is quite straight forward and obvious if you have a decent understanding of binary:

byte fourTimesThree = 0b1100;
byte data = 0b0000110011;
short number = 0b111111111111111; 
int overflow = 0b10101010101010101010101010101011;
long bow = 0b101010101010101010101010101010111L;

特別是在將類級別變量聲明為二進制文件這一點上,使用二進制表示法初始化靜態變量也絕對沒有問題:

And specifically on the point of declaring class level variables as binaries, there's absolutely no problem initializing a static variable using binary notation either:

public static final int thingy = 0b0101;

注意不要用太多數據溢出數字,否則你會得到一個編譯器錯誤:

Just be careful not to overflow the numbers with too much data, or else you'll get a compiler error:

byte data = 0b1100110011; // Type mismatch: cannot convert from int to byte

現在,如果您真的想變得花哨,您可以將 Java 7 中另一個被稱為數字文字的簡潔新功能與下劃線結合起來.看看這些帶有文字下劃線的二進制符號的奇特示例:

Now, if you really want to get fancy, you can combine that other neat new feature in Java 7 known as numeric literals with underscores. Take a look at these fancy examples of binary notation with literal underscores:

int overflow = 0b1010_1010_1010_1010_1010_1010_1010_1011;
long bow = 0b1__01010101__01010101__01010101__01010111L;

現在不是很好很干凈,更不用說高度可讀了嗎?

Now isn't that nice and clean, not to mention highly readable?

我從我在 TheServerSide 上寫的一篇關于該主題的小文章中提取了這些代碼片段.請隨時查看以獲取更多詳細信息:

I pulled these code snippets from a little article I wrote about the topic over at TheServerSide. Feel free to check it out for more details:

Java 7 和二進制表示法:掌握 OCP Java 程序員 (OCPJP) 考試

這篇關于在Java中,我可以用二進制格式定義一個整數常量嗎?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 婷婷久久五月天 | 91视视频在线观看入口直接观看 | 亚洲女人天堂网 | 久久久精彩视频 | 国偷自产av一区二区三区 | 午夜在线免费观看视频 | 91av视频在线观看 | 午夜免费视频 | 99亚洲精品 | 成人黄色av | 日韩 国产 在线 | 精品无码久久久久久久动漫 | 午夜在线精品偷拍 | 91在线精品视频 | 欧美精品久久久久久久久久 | 国产精品大全 | 亚洲激情视频在线 | 欧美午夜一区 | 欧美日韩美女 | 久久久久午夜 | 中文字幕av一区 | 日韩精品中文字幕一区二区三区 | 色综合视频 | 精品国产乱码久久久久久图片 | 伊人欧美视频 | 国产欧美精品在线观看 | 国产精品色| 91色视频在线观看 | 高清视频一区二区三区 | a在线视频| 五月婷亚洲| 这里有精品 | 日本精品在线观看 | 日韩成人在线观看 | 欧美一级在线免费 | 国内精品视频一区二区三区 | 日日av| 欧美日韩国产一区二区三区 | 中文字幕日韩欧美一区二区三区 | 亚洲区一区二区 | 精品一区二区在线观看 |