English Amiga Board


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

 
 
Thread Tools
Old 27 October 2019, 20:26   #1
peceha
Registered User

peceha's Avatar
 
Join Date: Dec 2017
Location: Poland
Age: 43
Posts: 208
[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, 22:15   #2
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,877
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 offline  
Old 27 October 2019, 22:17   #3
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,346
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, 22:25   #4
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,877
Is NOT bitwise, too? Then what would be the boolean "not" operator in Blitz?

In C ^ is the boolean not, ~ is bitwise.
thomas is offline  
Old 27 October 2019, 22:32   #5
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,346
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, 09:48   #6
thomas
Registered User
thomas's Avatar
 
Join Date: Jan 2002
Location: Germany
Posts: 5,877
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 offline  
Old 28 October 2019, 13:13   #7
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,346
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, 14:48   #8
Hedeon
PPC Hacker

 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,093
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, 15:35   #9
hooverphonique
ex. demoscener "Bigmama"

 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,001
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, 17:41   #10
Hedeon
PPC Hacker

 
Join Date: Mar 2012
Location: Leiden / The Netherlands
Posts: 1,093
So NOT could be bitwise, boolean and logical? ok.
Hedeon is offline  
Old 28 October 2019, 18:27   #11
hooverphonique
ex. demoscener "Bigmama"

 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,001
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, 18:48   #12
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,346
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
is this correct queston about small blitz basic code? JPQ Coders. Blitz Basic 0 08 October 2019 10:40
[blitz basic] How much amiga-blitz friendly is this? saimon69 Coders. Blitz Basic 104 29 November 2016 21:45
Translation to spanish formater support.WinUAE 0 07 July 2013 23:21
english translation laser support.Other 0 02 September 2008 20:32
WinUAE translation Carlos Ace support.WinUAE 1 14 July 2005 03: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 21:43.


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