Re: [OT] Bit twiddling homework

2018-07-21 Thread Peter J. Holzer
On 2018-07-20 19:13:44 +1000, Chris Angelico wrote: > On Fri, Jul 20, 2018 at 7:00 PM, Brian Oney via Python-list > wrote: > > That's right I had forgotten about that. Thank you for the quick > > answer.Some fun:$ ipythonPython 2.7.13 (default, Nov 24 2017, 17:33:09) > > ...In [1]: j = 16; i = 1

Re: [OT] Bit twiddling homework

2018-07-20 Thread jladasky
On Friday, July 20, 2018 at 2:00:26 AM UTC-7, Brian Oney wrote: > Are 16|1 and 16+1 internally the same operation (for integers)? For 16 and 1, the output of the two operations happen to be the same, but generally a bitwise OR is not the same are addition. There are no carry bits in the bitwis

Re: [OT] Bit twiddling homework

2018-07-20 Thread Grant Edwards
On 2018-07-20, Chris Angelico wrote: > On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards > wrote: >> On 2018-07-20, Dennis Lee Bieber wrote: >> >>> While I suspect Python isn't micro-optimizing, take into account >>> that most processors do have an "increment"/"decrement" operation -- >>> since th

Re: [OT] Bit twiddling homework

2018-07-20 Thread Chris Angelico
On Sat, Jul 21, 2018 at 2:39 AM, Marko Rauhamaa wrote: > Chris Angelico : > >> On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards >> wrote: >>> I refuse to believe there's an extant processor in common use where >>> an ADD is faster than an OR unless somebody shows me the processor >>> spec sheet. >>

Re: [OT] Bit twiddling homework

2018-07-20 Thread Marko Rauhamaa
Chris Angelico : > On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards > wrote: >> I refuse to believe there's an extant processor in common use where >> an ADD is faster than an OR unless somebody shows me the processor >> spec sheet. > > "Faster than"? I'd agree with you. But "as fast as"? I believe

Re: [OT] Bit twiddling homework

2018-07-20 Thread Brian Oney via Python-list
On Fri, 2018-07-20 at 10:38 -0400, Dennis Lee Bieber wrote: > On Fri, 20 Jul 2018 11:00:09 +0200, Brian Oney via Python-list > declaimed the following: > > > Are 16|1 and 16+1 internally the same operation (for integers)? > > For those integers the EFFECT/RESULT will be the same. But... >

Re: [OT] Bit twiddling homework

2018-07-20 Thread Chris Angelico
On Sat, Jul 21, 2018 at 1:14 AM, Grant Edwards wrote: > On 2018-07-20, Dennis Lee Bieber wrote: > >> While I suspect Python isn't micro-optimizing, take into account >> that most processors do have an "increment"/"decrement" operation -- >> since that is done so much at the low-level. Also, just

Re: [OT] Bit twiddling homework

2018-07-20 Thread Grant Edwards
On 2018-07-20, Dennis Lee Bieber wrote: > While I suspect Python isn't micro-optimizing, take into account > that most processors do have an "increment"/"decrement" operation -- > since that is done so much at the low-level. Also, just general > integer addition is common, so the hardware may be

Re: [OT] Bit twiddling homework

2018-07-20 Thread Brian Oney via Python-list
On Fri, 2018-07-20 at 18:07 +0900, xffox wrote: > On Fri, Jul 20, 2018 at 08:25:04AM +0200, Brian Oney via Python-list wrote: > > Therefore, what book or learning course do you recommend? I imagine > > something that tours or skims > > the fundamentals of Boolean algebra and digital logic, and the

Re: [OT] Bit twiddling homework

2018-07-20 Thread Ben Bacarisse
Brian Oney writes: > On Fri, 2018-07-20 at 06:37 +, Steven D'Aprano wrote: >> On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: >> >> > PS: Can I twiddle bits in Python? >> >> Yes. >> >> These operators work on ints: >> >> bitwise AND: & >> bitwise OR: | >> bi

Re: [OT] Bit twiddling homework

2018-07-20 Thread Chris Angelico
On Fri, Jul 20, 2018 at 7:00 PM, Brian Oney via Python-list wrote: > On Fri, 2018-07-20 at 06:37 +, Steven D'Aprano wrote: >> On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: >> >> > PS: Can I twiddle bits in Python? >> >> Yes. >> >> These operators work on ints: >> >> b

Re: [OT] Bit twiddling homework

2018-07-20 Thread xffox
On Fri, Jul 20, 2018 at 08:25:04AM +0200, Brian Oney via Python-list wrote: > Therefore, what book or learning course do you recommend? I imagine something > that tours or skims > the fundamentals of Boolean algebra and digital logic, and then goes to C and > some fun homework > problems. It may

Re: [OT] Bit twiddling homework

2018-07-20 Thread Brian Oney via Python-list
On Fri, 2018-07-20 at 06:37 +, Steven D'Aprano wrote: > On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: > > > PS: Can I twiddle bits in Python? > > Yes. > > These operators work on ints: > > bitwise AND: & > bitwise OR: | > bitwise XOR: ^ > That's right I ha

Re: [OT] Bit twiddling homework

2018-07-19 Thread Steven D'Aprano
On Fri, 20 Jul 2018 08:25:04 +0200, Brian Oney via Python-list wrote: > PS: Can I twiddle bits in Python? Yes. These operators work on ints: bitwise AND: & bitwise OR: | bitwise XOR: ^ -- Steven D'Aprano "Ever since I learned about confirmation bias, I've been seeing it everywhere

Re: [OT] Bit twiddling homework

2018-07-19 Thread Chris Angelico
On Fri, Jul 20, 2018 at 4:25 PM, Brian Oney via Python-list wrote: > PS: Can I twiddle bits in Python? You sure can! With most of the same operators that you would in C. The main difference is that Python's integers don't have word size limits; instead of working with, say, 32-bit integer, you j

[OT] Bit twiddling homework

2018-07-19 Thread Brian Oney via Python-list
Dear Python-List, an old dog wants to learn some new tricks. Due to my contact with microcontrollers, I am learning C/C++. I am aware that this is the endearing, helpful, yet chatty python-list. Many of you are competent C-programmers. The allure of C is that I can play directly with memory.