Sign in to follow this  
Followers 0
netegg

negetive add and subtract by using bit*

5 posts in this topic

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 this post


Link to post
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


Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

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

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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()
   Local $msg, $checkbox[3], $radio[5]
   GUICreate("My GUI Checkbox")
   $checkbox[0] = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20)
   For $i = 0 To 4
      $radio[$i] = GUICtrlCreateRadio('radio', 10, ($i + 2) * 20, 130.20)
      GUICtrlSetState(-1, $gui_disable)
   Next
   GUISetState()

   While 1
      $msg = GUIGetMsg()
      If $msg = $checkbox[0] Then
        For $i = 0 To 4
          ; GUICtrlSetState($radio[$i], BitShift(GUICtrlRead($checkbox[0]), -5) * (BitAND(GUICtrlRead($checkbox[0]), 1) + 1))
          ; GUICtrlSetState($radio[$i], BitShift(BitShift(GUICtrlRead($checkbox[0]), -5), - BitAND(GUICtrlRead($checkbox[0]), 1)))
           GUICtrlSetState($radio[$i],  BitShift(GUICtrlRead($checkbox[0]), -5-BitAND(GUICtrlRead($checkbox[0]), 1)))
        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 this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here another way to do it:

#include <guiconstantsex.au3>
Global $radio[5]
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
      $radio[$i] = GUICtrlCreateRadio('radio', 10, ($i + 2) * 20, 130.20)
      GUICtrlSetState(-1, $gui_disable)
   Next
   GUISetState()

   While 1
      $msg = GUIGetMsg()
      If $msg = $checkbox[0] Then
            $state = BitAND(GUICtrlRead($checkbox[0]), $GUI_CHECKED)
            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
                GUICtrlSetState($radio[$i], $GUI_ENABLE)
            Case Else
                GUICtrlSetState($radio[$i], $GUI_DISABLE)
        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
      $radio[$i] = GUICtrlCreateRadio('radio', 10, ($i + 2) * 20, 130.20)
      GUICtrlSetState(-1, $gui_disable)
   Next
   GUISetState()

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

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

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

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Thx, UEZ, Perfect!

Edited by netegg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0