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

在Java中,我可以用二進(jìn)制格式定義一個整數(shù)常量

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

問題描述

類似于如何用十六進(jìn)制或八進(jìn)制定義整數(shù)常量,我可以用二進(jìn)制來定義嗎?

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

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

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

推薦答案

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

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;

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

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;

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

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

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

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;

現(xiàn)在不是很好很干凈,更不用說高度可讀了嗎?

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

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

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 和二進(jìn)制表示法:掌握 OCP Java 程序員 (OCPJP) 考試

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

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

相關(guān)文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環(huán)繞文本?)
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 數(shù)據(jù)庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 精品色 | 久久国产精品免费一区二区三区 | 国产在线精品一区二区三区 | 国产精品永久免费 | 99精品一区二区 | 久久99国产精一区二区三区 | 欧美激情国产日韩精品一区18 | 久久久久久九九九九九九 | 一级高清免费毛片 | 亚洲v日韩v综合v精品v | 久久国产一区二区三区 | 精品国产一区二区三区久久 | 超碰精品在线观看 | 久久久久久国产精品 | 在线免费观看黄a | 国产一区二区在线观看视频 | 亚洲一区二区三区在线播放 | 欧美一区成人 | 亚洲精品成人在线 | 国产视频1区2区 | h视频免费看 | 亚洲一区亚洲二区 | 第四色播日韩第一页 | 一区久久 | 午夜在线小视频 | 国产亚洲第一页 | 国产一区91精品张津瑜 | 成人欧美一区二区三区在线播放 | 久久中文字幕电影 | 一区二区在线不卡 | 美女视频网站久久 | 精品国产一区二区三区免费 | 国产综合在线视频 | 亚洲色图婷婷 | 91文字幕巨乱亚洲香蕉 | 99精品免费在线观看 | 性视频一区 | 久久精品亚洲 | 国产精品中文字幕在线观看 | 欧美日韩久久久久 | 亚洲精品一二区 |