久久久久久久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(使用線程逐塊處理文件)
主站蜘蛛池模板: 久久精品一区二区国产 | 香港三日本三级少妇66 | 午夜在线视频观看 | 中国女人真人一级毛片 | 少妇高潮毛片 | 国产91页 | 久草福利在线视频 | 亚洲成在线 | 国产一区二区三区免费播放 | 亚洲综合精品 | 国产精品久久久久久久午夜 | 久在线 | 国产精品99久久久久久久久久久久 | 亚洲毛片在线 | 久久精品中文 | 中文字幕在线免费播放 | 亚洲成人免费av | 成人在线精品 | 伊人精品视频 | 久久久久久亚洲 | 99精品免费视频 | 免费看片黄色 | 亚洲精品免费在线 | 成人午夜网站 | 黄色片网站在线观看 | 看一级黄色片 | 精品欧美一区二区精品久久 | 国产视频一区二区在线观看 | 好色网站| 国产三级在线免费观看 | 国产成人精品一区二区三区在线 | 中文字幕免费 | 免费看黄色的视频 | 成年人视频网站 | 九九精品国产 | 日本www视频 | 欧美在线一级 | 一区二区三区免费在线观看 | 男男成人高潮片免费网站 | 1级黄色片 | 欧美一区二区三区在线 |