It 18 Palm Job _java Foundation fourth day _ review operator, binary conversion and array

Source: Internet
Author: User
Tags bitwise bitwise operators xms

1. Sort the bitwise operations, especially the left and right shifts (with or without symbols) to your blog.

The emphasis is on the operation process of clear negative numbers.


2.byte to hexadecimal string representation programming principles and implementation methods are organized into blogs.


3. Define a function to calculate the and of all elements of an integer array.

4. Copy of the array.


5. Heap memory default is 1/4,

----------------------------------------

java-xmx//Setting the maximum heap memory value

-xms//Setting the heap memory initial value

classname//class Name


----------------------


1, Answer:

The bitwise operators mainly have <<,>>,>>>,&,|,^, which are mainly operated in binary form during operation.

which

<<: shift left, vacancy 0, positive shift left corresponds to the process multiplied by 2,

However, if the sign bit is filled by 1 during the move, the positive number becomes negative.

Negative numbers may be negative during the left shift, depending on the binary form

>>: with the symbol right shift, the highest bit is 1, then the vacancy 1, the highest bit is 0, the vacancy is 0,

Positive shift or positive number, which corresponds to the process of dividing the power by 2. Negative sign right shift is still negative.

>>>: unsigned Right shift, no matter the highest bit is 0 or 1, the vacancy is 0 complement, positive unsigned right shift or positive,

Corresponding to the process divided by 2, negative unsigned right shifts become positive numbers.

&: Two binary numbers on the same bit, same as 1 o'clock, with a result of 1, with one 0 and a result of 0

| : Two binary numbers on the same bit, any accesses than either is 1, the result is 1, both are 0 o'clock and the result is 0

^: Two binary numbers on the same one, each other, the result is 1, the same result is 0,

Also ^ there is a property n ^m^ m=n, such as 1101 ^ 1000 = 0101,0101 ^ 1000 = 1101

Negative numbers are calculated as: the corresponding positive numbers are reversed plus one get, that is, a positive complement form.

2,byte number to hexadecimal string representation programming principle

/*

The byte type occupies 8 bits, and each hexadecimal digit has 4 bits components. So the byte type data is converted to 16 binary, up to two bits.

To remove the lower four bits of the byte number, you only need to perform a & operation with 1111, get to the lower four bits, and convert to hexadecimal by looking up the table method

Then take the high four bits of the byte number, first move the number to the right 4 bits, then with 1111 for & operations, get four bits high, by the table method to convert to hex


*/



Class Bytetohex

{

public static void Main (string[] args)

{

byte num = 127;

SYSTEM.OUT.PRINTLN ("Hexadecimal for num of type byte:" +bytetohex (num));

}

public static String Bytetohex (Byte num)

{

char[] CHS = new char[]{' 0 ', ' 1 ', ' 2 ',

' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 ',

' A ', ' B ', ' C ', ' d ', ' e ', ' f '};

Record the low four bits of the byte type variable num

int low = num & 0x0f;

Record the high four bits of the byte type variable num

num = (byte) (num >> 4);

int high = num &0x0f;

int high = (num >> 4) & 0x0f;

Return "" +chs[high]+chs[low];

}


}





3, defines the function, computes the and of all elements of an integer array.

Class Sumarray

{

public static void Main (string[] args)

{

int[] arr = new int[]{1,3,4,5,2,9};

System.out.println ("The and of all elements in the array is:" +getsumarray (arr));

}

public static int Getsumarray (int[] arr)

{

int sum=arr[0];

for (int i=1;i<arr.length;i++)

{

sum = Sum +arr[i];

}

return sum;

}

}



4, copy of array.

Class Copyarray

{

public static void Main (string[] args)

{

int[] arr1 = new int[]{1,3,4,5,8};

int[] arr2 = new Int[arr1.length];

PrintArray (ARR2);

System.out.println ("-------------");

PrintArray (Copyarray (ARR1,ARR2));

}

public static int[] Copyarray (int[] arr1, int[] arr2)

{

for (int i=0; i<arr1.length; i++)

{

Arr2[i]=arr1[i];

}

return arr2;

}

public static void PrintArray (int[] arr)

{

for (int i=0; i<arr.length; i++)

{

System.out.print (arr[i]+ "\ t");

}

System.out.println ();

}

}



5,


Setting the maximum memory value via java-xmx<size>

To set the heap memory initial value through java-xms<size>

Set stack memory size via java-xss<size>


This article is from the "Rookie Achievement Data Path" blog, please be sure to keep this source http://liubx.blog.51cto.com/11235064/1770340

It 18 Palm Job _java Foundation fourth day _ review operator, binary conversion and arrays

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.