Commonly used operation

xiaoxiao2021-03-06  15

Basic knowledge

Bit and operation standby and operators "&" are binocular operators. Its function is to participate in the two corresponding binary phases of the calculation. Only when the corresponding two bins are 1, the result is 1, otherwise 0. The number of participation in the calculation appears. For example: 9 & 5 can be writable as follows: 00001001 (9 binary complement) & 00000101 (5 binary complement) 00000001 (1 binary complement) Visible 9 & 5 = 1. Bit and operations are usually used to clear certain digits or hold certain bits. For example, a high eight digits of A, reserve low eight bits, can be used as A & 255 operation (255 binary number to 0000000011111111). [Example 12.1] In MIDP 1.0, we can only detect whether the button is pressed.

Here we can be a method similar to MIDP2.0

Store settings first

Public static final int game_a = 1 << canvas.game_a; public static final int game_b = 1 << canvas.game_b;

This reason we store the status of the button to the corresponding bit. In the process of application, when CANVAS is called KeyPressed ()

Protected void keypressed (int keycode) {// Set the key corresponding to 1 this.keystate = this.keyState | (1 << this.getgameAction (keycode)); // This button is released to 0 keyReleaseState = KeyreleaseState & ~ (1 << this.getgameAction (keycode);

This way we can use the getKeyStatus () method (own definition return keyState) to determine if the keyState & Game_a is 0 to determine if the button is pressed. When GAME_B is pressed simultaneously, it can also be applied.

转载请注明原文地址:https://www.9cbs.com/read-47011.html

New Post(0)