I wonder why the number increases by 48 when converting intchar type in JAVA Eclipse

Asked 2 years ago, Updated 2 years ago, 22 views

int a=1;
char b=(char)a;
int c=(int)b;

Debugging by load, c is 49 when b is 1, b is 2 and c is 50 initialized I'd appreciate it if you could tell me why this happened

java

2022-09-22 18:22

1 Answers

When b is 1, c is not 49; when b is 1, c is 49.

One character is stored as a number and replaced with a value in the ASCII table when the type is char.

As you can see from the table above, the letter "1" is 49 in decimal and 0x31 in hexadecimal. The letter '2' is a decimal number of 50.

If you add the number 1 to the letter 1, it becomes the letter 2 Add the number 32 to the letter 'A' to make the letter 'a'.


2022-09-22 18:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.