# negetive add and subtract by using bit*

## Recommended Posts

first, how to convert a negative int to binary, like -3, -5?

second, how to do subtract or add using bit* , as above -3-5 or -3 + (-5)?

##### Share on other sites

Have a look here: http://en.wikipedia.org/wiki/Binary_numeral_system

Use e.g. the highest bit to represent negative values.

16-bit:

0 000 0000 0000 0001 = 1

1 000 0000 0000 0001 = -1

Br,

UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

Thanks, uez,

This is my question. I've tried it two days, but can't I get a better solution.

a checkbox followed by group of radios, when unchecked checkbox, disable the radios,and enable when checked. Here is my code.

```#include <GUIConstantsEx.au3>
Example()
Func Example()
GUICreate("My GUI Checkbox")
\$checkbox[0] = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
For \$i = 0 To 4
GUICtrlSetState(-1, \$gui_disable)
Next
GUISetState()

While 1
\$msg = GUIGetMsg()
If \$msg = \$checkbox[0] Then
For \$i = 0 To 4
Next
EndIf
If \$msg = \$GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc   ;==>Example```

Pls have a look! I know there're some mistakes, but I can't get it!

Edited by netegg

##### Share on other sites

Here another way to do it:

```#include <guiconstantsex.au3>
Example()
Func Example()
Local \$msg, \$checkbox[3], \$state
GUICreate("My GUI Checkbox")
\$checkbox[0] = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
For \$i = 0 To 4
GUICtrlSetState(-1, \$gui_disable)
Next
GUISetState()

While 1
\$msg = GUIGetMsg()
If \$msg = \$checkbox[0] Then
Switch \$state
Case \$GUI_CHECKED
SetCtrlState(\$GUI_ENABLE)
Case Else
SetCtrlState(\$GUI_DISABLE)
EndSwitch
EndIf
If \$msg = \$GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc   ;==>Example

Func SetCtrlState(\$state)
Local \$i
For \$i = 0 To UBound(\$radio) - 1
Switch \$state
Case \$GUI_ENABLE
Case Else
EndSwitch
Next
EndFunc```

Or with bit operations:

```#include <guiconstantsex.au3>
Example()
Func Example()
Local \$msg, \$checkbox[3], \$radio[5], \$state, \$new
GUICreate("My GUI Checkbox")
\$checkbox[0] = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
For \$i = 0 To 4
GUICtrlSetState(-1, \$gui_disable)
Next
GUISetState()

While 1
\$msg = GUIGetMsg()
If \$msg = \$checkbox[0] Then
For \$i = 0 To UBound(\$radio) - 1
\$new = BitShift(\$GUI_ENABLE, -\$state) / (BitShift(\$state, -1)) ;BitShift(\$state, -1) ) = \$state * 2
Next
EndIf
If \$msg = \$GUI_EVENT_CLOSE Then ExitLoop
WEnd
EndFunc   ;==>Example```

Br,

UEZ

Edited by UEZ

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

##### Share on other sites

Thx, UEZ, Perfect!

Edited by netegg

## Create an account

Register a new account

• ### Recently Browsing   0 members

×

• Wiki

• Back

• #### Beta

• Git
• FAQ
• Our Picks
×
• Create New...