-
简化 java.lang.Short 类的源码
2020-09-28 03:19:58Short和Byte、Integer、Long一样由缓存值-128 ~ 127 public final class Short extends Number implements Comparable<Short> { @java.io.Serial private static final long serialVersionUID = ...Short和
Byte、Integer、Long
一样由缓存值-128 ~ 127
public final class Short extends Number implements Comparable<Short> { @java.io.Serial private static final long serialVersionUID = 7515723908773894738L; // 序列化版本号 public static final short MIN_VALUE = -32768; // 能够存储的最小值 public static final short MAX_VALUE = 32767; // 能够存储的最大值 private final short value; // 真正存储值得地方 public static final int SIZE = 16; // 占2个字节16位 public static final int BYTES = SIZE / Byte.SIZE; // 16/8=2个字节 @SuppressWarnings("unchecked") public static final Class<Short> TYPE = (Class<Short>) Class.getPrimitiveClass("short"); /** * 缓存值由来得代码 */ private static class ShortCache { private ShortCache() {} static final Short[] cache; static Short[] archivedCache; static { int size = -(-128) + 127 + 1; // 256 VM.initializeFromArchive(ShortCache.class); if (archivedCache == null || archivedCache.length != size) { Short[] c = new Short[size]; short value = -128; for(int i = 0; i < size; i++) { // 循环256次 c[i] = new Short(value++); // 缓存得-128 到 127存入数组中 } archivedCache = c; } cache = archivedCache; } } /** * 构造方法 */ @Deprecated(since="9") public Short(short value) {} // 将value直接赋值给成员变量 @Deprecated(since="9") public Short(String s) throws NumberFormatException{} // 将s按照10进制得方式解析成short赋值给value public byte byteValue() {} // 得到byte值 @HotSpotIntrinsicCandidate public short shortValue() {} // 得到short值 public int intValue() {} // 得到int值 public float floatValue() {} // 得到float值 public long longValue() {} // 得到long值 public double doubleValue() {} // 得到double值 @Override public int hashCode() {} // 得到当前值得hash值 public int compareTo(Short anotherShort) {} // 比较当前值和anotherShort得大小 public String toString() {} // 转换为字符串 public boolean equals(Object obj) {} // 判断当前值和obj是否相等 /** * 静态方法 */ public static String toString(short s) {} // 转换为字符串 public static short parseShort(String s, int radix){} // 按照radix进制解析字符串为short 可能解析失败 throws NumberFormatException public static short parseShort(String s) {} // 按照10进制解析字符串为short 可能解析失败 throws NumberFormatException public static Short valueOf(String s, int radix) {} // 按照radix进制解析字符串为Short 可能解析失败 throws NumberFormatException public static Short valueOf(String s) {} // 按照radix进制解析字符串为Short 可能解析失败 throws NumberFormatException @HotSpotIntrinsicCandidate public static Short valueOf(short s) {} // 将s封装为Short public static Short decode(String nm) {} // 将字符串nm节码,nm可以是十六进制得字符,也可以是10进制的... public static int hashCode(short value) {} // 得到value的hash值 public static int compare(short x, short y) {} // 比较x,y的大小 public static int compareUnsigned(short x, short y) {} // 比较无符号x,y的大小 @HotSpotIntrinsicCandidate public static short reverseBytes(short i) {} // 将i底层二进制按照字节进行逆序排序 public static int toUnsignedInt(short x) {} // 转换为无符号的int值 public static long toUnsignedLong(short x) {} // 转换为无符号的long值 }
-
C语言中char、short、int、long各占多少字节
2018-04-15 14:28:121byte = 8bit 一个字节...short:2个字节 int:4个字节 long:4个字节 以下是windows操作系统,32位机下的代码测试结果(32位机中,指针占4个字节,如变量e): windows操作系统,64位机中, char:1个字节 ...1byte = 8bit 一个字节占8个二进制位
windows操作系统,32位机中,
char: 1个字节
short: 2个字节
int: 4个字节
long: 4个字节
以下是windows操作系统,32位机下的代码测试结果(32位机中,指针占4个字节,如变量e):
windows操作系统,64位机中,
char: 1个字节
short: 2个字节
int: 4个字节
long: 4个字节
以下是windows操作系统,64位机下的代码测试结果(64位机中,指针占8个字节,如变量e):
此处感谢用户名为“shcdwz1234”以及“此昵称已经被人使用”的批评指正,之前的博文中,我写:“64位机环境下,long占据8个字节”,当时写这个博文时没有用代码进行测试验证,从其他人的博客中复制过来的,验证发现,64位机环境下,long占据4个字节。
我以后会吸取教训,写会影响到阅读者的博文前,会先测试验证。
再次感谢!
2019-12-24补充:
经用户名为“hall919”的朋友提醒,他在ubuntu 18.04,64位 环境下测试,long占据8个字节。网上搜索发现,long占据的字节数还和编译器的数据模型相关,具体如下:
Datetype LP64 ILP64 LLP64 ILP32 LP32 char 8 8 8 8 8 short 16 16 16 16 16 int 32 64 32 32 16 long 64 64 32 32 32 long long 64 pointer 64 64 64 32 32 一般情况下windows64位一般使用LLP64模型
64位Unix,Linux使用的是LP64模型
参考博文:https://blog.csdn.net/akyj1021/article/details/81432758 -
Char是short short
2013-12-05 15:39:43C语言中有long long数据类型,但是没有short short,而实际上的short short是char,8位整数。在赵岩老师的《C语言点滴》一书中,我第一次见到“Char是short short”这样的说法,虽然学C的时候就知道char本质是整型数...C语言中有long long数据类型,但是没有short short,而实际上的short short是char,8位整数。在赵岩老师的《C语言点滴》一书中,我第一次见到“Char是short short”这样的说法,虽然学C的时候就知道char本质是整型数。
同时,getchar()函数原型的返回值是int型,因为char可能在某些平台下为无符号数,而无法接收EOF这个值为-1的标记。
-
c# short_C#中的short关键字
2020-07-29 10:01:08c# short C#短关键字 (C# short keyword) In C#, short is a keyword which is used to declare a variable that can store a signed integer value between the range of -32,768 to 32,767. short keyword is an ...c# short
C#短关键字 (C# short keyword)
In C#, short is a keyword which is used to declare a variable that can store a signed integer value between the range of -32,768 to 32,767. short keyword is an alias of System.Int16.
在C#中, short是一个关键字,用于声明一个变量,该变量可以存储介于-32,768到32,767之间的有符号整数值。 short关键字是System.Int16的别名。
It occupies 2 bytes (16 bits) space in the memory.
它在内存中占用2个字节(16位)的空间。
Syntax:
句法:
short variable_name = value;
C#代码演示短关键字示例 (C# code to demonstrate example of short keyword)
Here, we are declaring a short variable num, initializing it with the value 12345 and printing its value, type and size of a short type variable.
在这里,我们宣布一个短变量num,与价值12345初始化它和印刷短类型的变量它的价值,类型和大小。
using System; using System.Text; namespace Test { class Program { static void Main(string[] args) { //variable declaration short num = 12345; //printing value Console.WriteLine("num: " + num); //printing type of variable Console.WriteLine("Type of num: " + num.GetType()); //printing size Console.WriteLine("Size of a short variable: " + sizeof(short)); //printing minimum & maximum value of short Console.WriteLine("Min value of short: " + short.MinValue); Console.WriteLine("Max value of short: " + short.MaxValue); //hit ENTER to exit Console.ReadLine(); } } }
Output
输出量
num: 12345 Type of num: System.Int16 Size of a short variable: 2 Min value of short: -32768 Max value of short: 32767
翻译自: https://www.includehelp.com/dot-net/short-keyword-in-c-sharp.aspx
c# short
-
java Short详解
2019-08-27 11:53:39public class ShorDamo { static void m1() { Short short1=new Short((short) 23); Short short2=new Short("12"); System.out.println(short1); System.out.println(short2); } p... -
Java Short类shortValue()方法及示例
2020-07-10 00:52:01短类shortValue()方法 (Short class shortValue() method) shortValue() method is available in java.lang package. shortValue()方法在java.lang包中可用。 shortValue() method is used to return the value ... -
Short类
2015-10-02 12:58:02同样,该类继承Number类,实现Comparable(Short)接口。属性:public static final short MAX_VALUE = (short) 0x7FFF;public static final short MIN_VALUE = (short) 0x8000;public static final int SIZE = 16;... -
short与Unsigned short以及Java基本类型
2019-06-15 09:53:05short两个字节长度,其中符号位占了一位。所以实际数值位数是15位。取值范围为:-32768~+32768。 unsigned short没有符号位,所以实质数值位数是16位。取值范围:0~65536。 Java中的基本类型都是有符号类型,也就是... -
Short源码解析
2019-05-07 15:17:50此外,该类还提供了几种将short转换为String和String转换为short ,以及在处理short时有用的其他常数和方法。short 数据类型是 16 位、有符号的以二进制补码表示的整数。 类图结构: 源码解析: package java.lang;... -
深度学习与时间序列 Long short-term memory Conference 2017
2019-12-14 16:08:062017 Yangdong Liu; Yizhe Wang; Xiaoguang Yang;... Short-term travel time prediction by deep learning: A comparison of different LSTM-DNN models. Intelligent Transportation Systems (... -
(十六)Modeling Long- and Short-Term Temporal Patterns with Deep Neural Networks(LSNet)
2020-06-05 16:18:46相关PPT已经上传,可以在我...论文链接:Modeling Long- and Short-Term Temporal Patterns with Deep Neural Networks 代码链接:https://github.com/laiguokun/LSTNet 解析论文的参考的论文: 参考一:https://zhuanl -
C语言基本数据类型short、int、long、char、float、double
2016-01-21 02:00:381.概述 C 语言包含的数据类型如下图所示 ... short a=1; 2.1.2整形 一般占4个字节(32位),最高位代表符号,0表示正数,1表示负数,取值范围是-2147483648~2147483647,在内存中的存储顺序是地位在前、高 -
数据库字段short与Short类型区别
2017-11-01 15:50:42采用自动生成的SQL语句,自动生成的数据库model中该字段类型会默认为short。 在插入数据时,该字段没有值时会,默认设置为0. 这时 如果数据库中有两个字段A和B 且都是smallint型。 第一次插入数据 两个字段不... -
JAVA中short和short相加自动转化为int
2017-05-08 19:49:16JAVA中short和short相加自动转化为int 标签: JAVA 2016-06-20 00:48 918人阅读 评论(0) 收藏 举报 对于short s1 = 1; s1 = s1 + 1; 由于s1+1运算时会自动提升表达式的类型,所以结果是... -
unsigned short int与short int转化问题和unsigned int与int相加问题
2018-06-05 16:58:46unsigned short int与short int转化问题和unsigned int与int相加问题1、unsigned short int与short int转化问题unsigned short int a=65535转化为short int型是多少呢?unsigned short int的字节数为2,取值范围是0... -
Short.compare NoSuchMethodError
2019-03-15 11:07:04项目中需要对数据排序,故需要比较数据属性值的一些大小,而看到Short/Integer/Long/Boolean这些类中,有compare方法可以使用,于是用了起来。 Crash 4.3及以下系统版本,运行到Short.compare时,程序崩溃,堆栈如下... -
JDK源码阅读之Short
2019-09-03 15:39:15Short是基本类型short的包装类,现在我们一起看看它的源码吧!你将收获关于Short的细节哦 -
java int转Short
2019-08-03 11:39:00使用short(xx) problemMultipleChoiceDO.setExamCount((short)0);//在数据库中是smallint类型 转载于:https://www.cnblogs.com/yang101/p/11294292.html -
Java short数据类型
2017-03-22 09:05:41短(short)整型数据类型是16位有符号Java原始整数数据类型。 其范围是-32768至32767(或-2^15至2^15-1)。 short整型数据类型没有字面量。但是,可以将任何位于short(-32768到32767)范围内的int数值分配给一个短... -
int(Integer) 与 short(Short)
2013-12-06 16:55:14int 是4字节, short 是2字节的, 如果将int(Integer)转成short(Short), 那么必须强制转换,否则会报编译异常。 但是, 当int(Integer)是一个final时, 可以直接转换, 不必强转。如: short t = 1;(正确... -
Java - short s = 1; s = s + 1; 有错吗? short s = 1; s += 1; 有错吗?
2019-03-07 10:22:10分享一个大牛的人工智能教程。零基础!通俗易懂!... 由于1是int类型,因此s + 1运算结果也是int型,需要强制类型转换才能赋值给short型。而short s= 1; s+= 1; 可以正确编译,因为 s+= 1; 相当于 s= (s... -
负数short转Integer
2018-11-13 10:48:06跟其他语言对接通讯接口过程中,因java是有... * short转integer(考虑到short可能会超出范围特殊处理下) * @param s * @return */ public static Integer shortToInteger(Short s){ if(s < 0){ ret... -
Short URL implement
2012-04-27 13:55:27Few months ago, I introduced a simple algorithmthat allow users to implement their own short URL into their system. Today,I have some spare time so I decided to write the short URL algorithm'... -
C# ShortTime LongTime ShortDate LongDate 的区别
2017-08-09 14:59:04string time = "2017/7/10 18:38:44"; DateTime t = DateTime.Parse(time); ...MessageBox.Show(t + " shorttime" + t.ToShortTimeString() + " longtime" + t.ToLongTimeString()+" shortD -
Integer怎么转化成short
2020-01-19 14:41:47调用Integer类的shortValue()方法即可得到其short值,这个方法是覆盖了其父类Number的方法 -
Short GI
2013-06-04 20:15:48Short GI介绍 英文:GI:(Guard Interval) 中文:保护间隔 是802.11n针对802.11a/g所做的改进。本代码是基于OFDM系统的一种转换域估计算法,有整个OFDM系统及改进的信道估计算法仿真。包括LS,MMSE,LMMSE,DFT... -
从JDK源码角度看Short
2017-08-01 20:25:31概况Java的Short类主要的作用就是对基本类型short进行封装,提供了一些处理short类型的方法,比如short到String类型的转换方法或String类型到short类型的转换方法,当然也包含与其他类型之间的转换方法。继承结构--... -
C# 从 short 转 byte 方法
2019-04-29 12:09:41本文告诉大家多个方法转换 short 和 byte 有简单的也有快的 -
ERC20 Short Address Attack
2019-05-23 20:30:19ERC20 Short Address Attack什么是ERC20Application Binary Interface(ABI)ERC20 Short Address Attack开始攻击怎么利用?攻击防范 什么是ERC20 代币大家应该都很熟悉了,代币也叫 token, 他不是像比特币,以太坊等...
-
如何解决设计难点(第三部分).pdf
-
基本的MySQL语句
-
MySQL 性能优化(思路拓展及实操)
-
FrameWork.zip
-
程达--自动化运维.txt
-
json handle.zip
-
C#Winform桌面开发编程上位机基础入门
-
如何拥有系统化开发能力(第二部分).pdf
-
工信部下架 10 款侵害用户权益 App: 因未按要求完成整改 看看你有没有中枪!!
-
双子-iptv.TV直播系统服务器系统
-
404页面设置方法_404页面案例
-
【剑指offer】面试题13 - 机器人的运动范围
-
MySQL 高可用工具 DRBD 实战部署详解
-
LVRTE2015_f3Patchstd.zip
-
meteor安装serialport失败
-
css_lower.zip
-
MySQL 高可用工具 heartbeat 实战部署详解
-
MySQL 设计基础(数据库概论、初探)
-
《文件和目录操作命令》
<2.> -
基于SSM实现的房屋租赁系统【附源码】(毕设)