Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Type conversion in Java

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article will explain in detail how to implement type conversion in Java, the quality of the article content is high, so Xiaobian shares it for everyone to make a reference, I hope you have a certain understanding of related knowledge after reading this article.

public class Change {

public static void main(String[] args) {

byte a = (byte)-1;

System.out.println(a);

char b =(char)a;

System.out.println(b);

int c = (int)b;

System.out.println(c);

}

}

Take a look at the output:

Here's an explanation of the problem:

Step 1: int type-1 strong to byte type or-1

The second part: byte type-1 converted to char, by ascii code table,-1 is not in the table range, because the default char accounts for 2 bytes, that is, 8 bits, the maximum value that can be stored is 65536, so the char number range is 0-65535, turn-1 into char, will look backwards, that is, the maximum value 65535,

Step 3:65535 of char type converted to int or 65535

ASCII code comparison table

basic data type byte size byte1 byte minimum is-128 (-2^7); maximum is 127 (2^7-1);boolean at least 1 byte This type is used only as a flag to record true/false conditions;short2 bytes minimum is-32768 (-2^15); maximum is 32767 (2^15 - 1);char2 bytes minimum is\u0000 (i.e. 0); maximum is\uffff (i.e. 65,535);int4 bytes minimum is-2,147,483,648 (-2^31); maximum is 2,147,483,647 (2^31 - 1);float4 byte single-precision floating-point number 32 bits long, mantissa length 23, exponent length 8, exponent offset 127;long8 bytes minimum is-9,223,372,036,854,775,808 (-2^63); maximum is 9,223,372,036,854,775,807 (2^63 -1); double4-byte double-precision floating point number 64 bits long, mantissa length 52, exponent length 11, exponent offset 1023;

English letters:

Number of bytes: 1; Code: GB2312

Number of bytes: 1; Code: GBK

Number of bytes: 1; Code: ISO-8859-1

Number of bytes: 1; encoding: UTF-8

Chinese characters:

Number of bytes: 2; Code: GB2312

Number of bytes: 2; Code: GBK

Number of bytes: 1; Code: ISO-8859-1

Number of bytes: 3; encoding: UTF-8

About Java how to achieve type conversion to share here, I hope the above content can be of some help to everyone, you can learn more knowledge. If you think the article is good, you can share it so that more people can see it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report