Issue #6361 has been updated by MartinBosslet (Martin Bosslet).


nobu (Nobuyoshi Nakada) wrote:
> 
> What you want seems (({BitArray})), not a kind of char string.
>

Thought the same, sounds much like this[1].

I think having both bit and byte operations in the same class at the same time would become a mess real soon. But apart from the "resolution" (bit, byte, multi-byte) the operations one would wish to perform on the array/vector are pretty much the same everywhere. So I had this idea: what if we made the resolution a parameter on initialization, and this would determine the further behavior? Something like

  bits = ByteString.new(2)
  bits[7] = 1 #Sets the 8th bit to 1, argument may only be in the range 0..1 (= [0;2^1 - 1])
  bits[2] = 1 #Sets the 3rd bit to 1

  bytes = ByteString.new(8)
  bytes[0] = 0xcc #Sets the first byte to 0xcc, arguments are in the range of 0..255 (=[0;2^8-1])

  uint32s = ByteString.new(32)
  uint32s[0] = 65536 #Sets the first word (32bit) to 65536, arguments are in the range [0;2^32-1])

  ...

  The initialization parameter would be a power of two that indicates the "width" in bits of a single unit of data that you wish to manipulate.

  The behavior of "xor", "and", "or", "not" would follow naturally and would be implied by the underlying "resolution". This allows everyone to have their version of what fits best in their current domain, much like pack/unpack does.
   
[1] http://docs.oracle.com/javase/6/docs/api/java/util/BitSet.html
----------------------------------------
Feature #6361: Bitwise string operations
https://bugs.ruby-lang.org/issues/6361#change-26468

Author: MartinBosslet (Martin Bosslet)
Status: Feedback
Priority: Normal
Assignee: 
Category: core
Target version: 


I know this has been discussed a lot in the past (and if there's still 
an open issue for this, I apologize, I couldn't find one), for example
in [1]. While it is generally no problem to implement this on the fly,
I still find that built-in support would be a real improvement. There
are quite some use cases in cryptography where this would come in very
handy, but I'm sure there are lots of other areas, too.

While of course I understand the reasons that were given in the previous
threads that ultimately lead to rejection, I still would like to reopen
the discussion as I felt that in every thread so far the consensus was
that having bitwise string operations would indeed be quite valuable. 

[1] http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/34586


-- 
http://bugs.ruby-lang.org/