27 October 2019, 19:26 | #1 |
Registered User
Join Date: Dec 2017
Location: Poland
Age: 47
Posts: 282
|
[blitz] need a small translation from c
Hi,
Code:
SerReq->io_SerFlags &= ~SERF_PARTY_ON SerReq->io_SerFlags |= SERF_XDISABLED Code:
*sereq\io_SerFlags = *sereq\io_SerFlags & NOT #SERF_PARTY_ON *sereq\io_SerFlags = *sereq\io_SerFlags | #SERF_XDISABLED Thanks |
27 October 2019, 21:15 | #2 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
No, these are bit-wise operations, not boolean.
x &= ~y clears every bit in x that is set in y x |= y sets every bit in x that is set in y. |
27 October 2019, 21:17 | #3 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
That looks correct to me anyway, but I haven't tested it...
Edit: Hmmm, maybe my brain's tired now, but thomas' post has me thinking. I still can't see that it's any different - & and | operate in a bitwise fashion in Blitz. |
27 October 2019, 21:25 | #4 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
Is NOT bitwise, too? Then what would be the boolean "not" operator in Blitz?
In C ^ is the boolean not, ~ is bitwise. |
27 October 2019, 21:32 | #5 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
yes, NOT is bitwise too. It works in boolean expressions because true is accepted to be any non-zero value, but is always returned as -1. So a bitwise NOT of -1 will equate to 0 / false. So:
Code:
If NOT x = y Then NPrint "Not equal" Code:
NPrint Bin$(NOT %10000000) |
28 October 2019, 08:48 | #6 |
Registered User
Join Date: Jan 2002
Location: Germany
Posts: 6,985
|
This is a contradiction in itself. If any non-zero value is true, then 2 is true, too. If NOT is bitwise, then NOT 2 is -3 which is still true. So NOT does not work in boolean expressions. It only works if TRUE (a.k.a. -1) has been returned by a comparison.
|
28 October 2019, 12:13 | #7 | |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
When you put it like that, indeed, but my point was made in the rest of the sentence after that:
Quote:
|
|
28 October 2019, 13:48 | #8 |
Semi-Retired
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,993
|
|
28 October 2019, 14:35 | #9 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
|
28 October 2019, 16:41 | #10 |
Semi-Retired
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,993
|
So NOT could be bitwise, boolean and logical? ok.
|
28 October 2019, 17:27 | #11 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
|
28 October 2019, 17:48 | #12 |
Registered User
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
|
Yeah, the names can be a little confusing. Boolean is a *type* of logic, where you can only have two values, true or false, 1 or 0. A boolean variable is one which is essentially 1 bit. In computing terms, "logical" is usually used to describe operations where each entire term is taken as boolean, so each value can be either true or false, regardless of what arrangement of bits they actually contain. "Bitwise" is used to refer to operations that focus on the individual bits of a value, rather than what it represents overall. C has explicit operators that differentiate the two, ! is (boolean) logical NOT and ~ is bitwise NOT. Blitz doesn't really have that same concept of boolean values, and so internally represents true as -1 and false as 0. So something like
Code:
NPrint 5>3 Code:
NPrint NOT 5>3 This works for all Blitz operations that are boolean in nature, however it does mean that Blitz can't check for a zero value by doing e.g. NOT filehandle as is common in C (!filehandle). Instead, filehandle <> 0 is used. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
[blitz basic] How much amiga-blitz friendly is this? | saimon69 | Coders. Blitz Basic | 105 | 21 April 2022 19:45 |
is this correct queston about small blitz basic code? | JPQ | Coders. Blitz Basic | 0 | 08 October 2019 09:40 |
Translation to spanish | formater | support.WinUAE | 0 | 07 July 2013 22:21 |
english translation | laser | support.Other | 0 | 02 September 2008 19:32 |
WinUAE translation | Carlos Ace | support.WinUAE | 1 | 14 July 2005 02:12 |
|
|