English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 27 October 2019, 19:26   #1
peceha
Registered User
 
peceha's Avatar
 
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
is it like:
Code:
*sereq\io_SerFlags = *sereq\io_SerFlags & NOT #SERF_PARTY_ON
*sereq\io_SerFlags = *sereq\io_SerFlags | #SERF_XDISABLED
?

Thanks
peceha is offline  
Old 27 October 2019, 21:15   #2
thomas
Registered User
 
thomas's Avatar
 
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.
thomas is online now  
Old 27 October 2019, 21:17   #3
Daedalus
Registered User
 
Daedalus's Avatar
 
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.
Daedalus is offline  
Old 27 October 2019, 21:25   #4
thomas
Registered User
 
thomas's Avatar
 
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.
thomas is online now  
Old 27 October 2019, 21:32   #5
Daedalus
Registered User
 
Daedalus's Avatar
 
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"
Works because x = y is evaluated as -1 or 0, as does
Code:
NPrint Bin$(NOT %10000000)
Daedalus is offline  
Old 28 October 2019, 08:48   #6
thomas
Registered User
 
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 6,985
Quote:
Originally Posted by Daedalus View Post
NOT is bitwise too. It works in boolean expressions because true is accepted to be any non-zero value
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.
thomas is online now  
Old 28 October 2019, 12:13   #7
Daedalus
Registered User
 
Daedalus's Avatar
 
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:
, but is always returned as -1
Boolean expressions are always returned to the evaluation as true or false. If the terms you NOT are just boolean, then it's a boolean operation. If you try to NOT anything non-boolean, then it's bitwise. Context is key.
Daedalus is offline  
Old 28 October 2019, 13:48   #8
Hedeon
Semi-Retired
 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,993
Quote:
Originally Posted by thomas View Post
In C ^ is the boolean not, ~ is bitwise.
What is ! and what is 'exclusive or' bitwise? I am still learning but I thought ^ was something else?
Hedeon is offline  
Old 28 October 2019, 14:35   #9
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by Hedeon View Post
What is ! and what is 'exclusive or' bitwise? I am still learning but I thought ^ was something else?
in C, ! is logical not, ^ is bitwise xor.
hooverphonique is offline  
Old 28 October 2019, 16:41   #10
Hedeon
Semi-Retired
 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,993
So NOT could be bitwise, boolean and logical? ok.
Hedeon is offline  
Old 28 October 2019, 17:27   #11
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by Hedeon View Post
So NOT could be bitwise, boolean and logical? ok.
What is referred to as 'boolean' above is the equivalent of my 'logical', I think. Boolean logic applies to both bitwise and logical operators, so it may be a bit misleading calling one of them 'boolean'.
hooverphonique is offline  
Old 28 October 2019, 17:48   #12
Daedalus
Registered User
 
Daedalus's Avatar
 
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
will produce -1 as the output, because 5 is greater than 3. The reason it does this is that -1 (true) is represented in binary as all ones (%11111111), and 0 (false) is represented as all zeroes (%00000000). Thus, doing a bitwise NOT (flipping every bit in the value) swaps true to false and false to true. So
Code:
NPrint NOT 5>3
will output 0.
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.
Daedalus is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 09:08.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.25815 seconds with 13 queries