Mantis - Squeak
Viewing Issue Advanced Details
6985 Kernel feature N/A 03-20-08 23:17 04-18-10 22:04
nicolas cellier  
nicolas cellier  
normal  
closed 3.10  
fixed  
none    
none trunk  
0006985: [NEW FEATURE] Integer bitAt:

This is a simple feature that is missing:
bitAt: n answers 1 if nth bit is 1, 0 otherwise.
Negatives act as two complements, also LargeNegativeInteger.

I propose a naive version in Integer, optimized in subclasses.
 Integer_bitAt_M6985-nice.1.cs [^] (3,058 bytes) 03-21-08 00:03
 Integer_bitAt_Test_M6985-nice.1.cs [^] (1,763 bytes) 03-21-08 00:03
 Integer_bitAt_M6985-nice.2.cs [^] (2,312 bytes) 03-21-08 20:51
 Integer-raisedTo-modulo-speedUp-M7120-nice.1.cs [^] (3,078 bytes) 07-12-08 00:38

Notes
(0011943)
nicolas cellier   
03-21-08 00:10   
"fix begin"
Installer mantis bug: 6985 fix:'Integer_bitAt_M6985-nice.1.cs'.
"fix test"
Installer mantis bug: 6985 fix:'Integer_bitAt_Test_M6985-nice.1.cs'.
"fix end"

(0011944)
bonzini   
03-21-08 08:31   
If you write the Integer version as

(self bitShift: 1 - anInteger) bitAnd: 1

then you can avoid overriding the method in SmallInteger.
(0011947)
nicolas cellier   
03-21-08 20:53   
"Ah yes, better. Thanks!"

"fix begin"
Installer mantis bug: 6985 fix:'Integer_bitAt_M6985-nice.2.cs'.
"fix test"
Installer mantis bug: 6985 fix:'Integer_bitAt_Test_M6985-nice.1.cs'.
"fix end"

(0013358)
nicolas cellier   
10-06-09 10:25   
Fixed in http://source.squeak.org/trunk/Kernel-nice.262.mcz [^]
and http://source.squeak.org/trunk/KernelTests-nice.99.mcz [^]