Java escape character and binary conversion

Source: Internet
Author: User
Tags bitwise operators

One: Escape character

\ r means accept keyboard input, equivalent to press ENTER.

\ n indicates a line break.

\ t tab, equivalent to Table key

\b backspace key, equivalent to back Space

\ ' single quotation mark

\ ' double quotes

\ \ represents a diagonal cross

Note: The line break is another line, the carriage return is the beginning of a line, so we usually write a file carriage return should be exactly called carriage return line break

Second: The conversion of the binary

The representation of an integer constant: a binary representation (binary, octal, decimal, hexadecimal)

Conversions between the binaries:

decimal into binary: Divide the decimal by 2until the quotient is 0 , and the remainder is concatenated from the bottom to the binary.

Ten---->1010

Binary to decimal: Multiplies each bit of the binary by 2^n, N starts at 0 ,n adds one each time , and adds the result.

1001----" 1*2^0 +0*2^1 +0*2^2+1*2^3 = 9

Binary transposition octal:

way 1:2 binary ---> decimal ---> octal

Mode two: An octal equivalent of three binary for, will be binary three bit a split, calculated

010 100 101 = 245

swap binary to hexadecimal : (0-9) (A (ten)-F (15))

0000 1010 0101 = A5

Three: Bitwise operators

& ( with ): Both are 1 When I am one, the others are 0

| ( or ) : Both are 0 only when the 0 , the others are 1.

^ ( xor ): The difference between the two is 1, the same as 0

~ ( inverse ):0 becomes 1,1 becomes 0.

The representation of negative numbers: The highest bit of bits is 1, then this number is a negative.

1111-1111 1111-1111 1111-1111 1111-1111 : -1

0000 0000 0000 0000 0000 0000 0000 0000 : 0

-2:1111-1111 1111-1111 1111-1111 1111-1110

-3:1111-1111 1111-1111 1111-1111 1111-1101

-4:1111-1111 1111-1111 1111-1111 1111-1100

-5:1111-1111 1111-1111 1111-1111 1111-1011

-6:1111-1111 1111-1111 1111-1111 1111-1010

-7:1111-1111 1111-1111 1111-1111 1111-1001

0000-0000 0000-0000 0000-0000 0000-0111 = 7

1111-1111 1111-1111 1111-1111 1111-1001

rule: Negative number corresponding to the positive number-1 , take the inverse

negative number corresponding to the positive negation +1

Role: Data is encrypted

four: shift operator : operation on Bits

1.6.1 >> Right Shift

1.6.2 << left Shift

1.6.3 >>> unsigned Right shift

>> Right Shift

<< left Shift

>>> unsigned Right shift

Move Right:

System.out.println (6>>1); --->3 6/2 2*1

System.out.println (6>>2); --->1 6/4 2*2

System.out.println (6>>3); --->0 6/8 2*3

System.out.println (6>>4);

System.out.println (9>>1); --->4 9/2 2*1

System.out.println (9>>2); --->2 9/4 2*2

System.out.println (9>>3); --->1 9/8 2*3

System.out.println (9>>4);//--->0 9/16

System.out.println ( -6>>1); -6/2-->-3

rule: Shift the number of digits to the right by dividing by 2 How many times you need to move.

Move Left:

SYSTEM.OUT.PRINTLN ("----- This is the result of the left shift ----------");

System.out.println (6<<1); --->12 6*2 2*1

System.out.println (6<<2); --->24 6*4 2*2

System.out.println (6<<3); --->48 6*8 2*2*2

System.out.println (6<<4); ---->96 6*16 2*2*2*2

Ystem.out.println ( -6<<2);//--->-24

rule: How many digits to the left, multiply this number by 2 times.

>>> unsigned Right shift

System.out.println (6>>>1); 3

System.out.println (6>>>2); 1

System.out.println ( -6>>>2); 1073741822

function : increases the operation rate. Bit arithmetic is the fastest execution.

For example: calculate 2*8 in the quickest way

2<<3 = = 2*8 = 16

features : A number A and two the same number ^, the final result is still the original number a.

Java escape character and binary conversion

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.