Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

Bitwise operations

 [1/9] from: ptretter::charter::net at: 14-Aug-2003 15:05


I think REBOL needs more native functions for handling bitwise operations. Such as bitwise shift operators (>>= <<=) . Also we need enbase debase functions for handling integer data or refinements for to-binary such as: to-binary/base 128 2
>>#{10000000}
Just some thoughts. Maybe I'm overlooking some functions. Paul Tretter

 [2/9] from: greggirwin:mindspring at: 14-Aug-2003 15:08


Hi Paul, PT> I think REBOL needs more native functions for handling bitwise operations. PT> Such as bitwise shift operators (>>= <<=) . SHIFT and ROTATE functions could be very handy, and could be applied to series! values as well as bitsets. When I started with REBOL, I cooked up simple mezzanines for that purpose (series only; no bitset support). -- Gregg

 [3/9] from: andrew:martin:colenso:school at: 15-Aug-2003 9:22


Paul wrote:
> I think REBOL needs more native functions for handling bitwise
operations. Does Rebol really need it? Wouldn't it be better to use Assembler, C or C++ for that kind of job? Bit-twiddling usually means that one is interfacing with hardware, and it's usually best to use a language that's closer to the "metal" as it were and one that's very, very fast. Just my opinion. Andrew J Martin Attendance Officer & Information Systems Trouble Shooter Colenso High School Arnold Street, Napier. Tel: 64-6-8310180 ext 826 Fax: 64-6-8336759 http://colenso.net/scripts/Wiki.r?AJM http://www.colenso.school.nz/ DISCLAIMER: Colenso High School and its Board of Trustees is not responsible (or legally liable) for materials distributed to or acquired from user e-mail accounts. You can report any misuse of an e-mail account to our ICT Manager and the complaint will be investigated. (Misuse can come in many forms, but can be viewed as any material sent/received that indicate or suggest pornography, unethical or illegal solicitation, racism, sexism, inappropriate language and/or other issues described in our Acceptable Use Policy.) All outgoing messages are certified virus-free by McAfee GroupShield Exchange 5.10.285.0 Phone: +64 6 843 5095 or Fax: +64 6 833 6759 or E-mail: [postmaster--colenso--school--nz]

 [4/9] from: ptretter:charter at: 14-Aug-2003 16:40


Actually, I got a small project right now where I'm working with binary data that is then converted to text. REBOL obviously is very up to the task of parsing so its preferred. But the binary data is encoded and I need to decode it. Therefore, would be another useful tool to REBOL. Paul Tretter

 [5/9] from: greggirwin:mindspring at: 14-Aug-2003 15:58


Hi Andrew, AM> Does Rebol really need it? Wouldn't it be better to use Assembler, C or AM> C++ for that kind of job? Bit-twiddling usually means that one is AM> interfacing with hardware, and it's usually best to use a language AM> that's closer to the "metal" as it were and one that's very, very fast. Bit vectors are a handy, space efficient, structure that you can use for lots of things. They can also be handy for interfacing to libraries. When I have to do something that makes me jump through hoops to do it, then I'll really want it. Until then, I can see it as a nice-to-have feature. -- Gregg

 [6/9] from: krobillard:cox at: 14-Aug-2003 15:50


On Thursday 14 August 2003 02:22 pm, you wrote:
> Paul wrote: > > I think REBOL needs more native functions for handling bitwise
<<quoted lines omitted: 4>>
> that's closer to the "metal" as it were and one that's very, very fast. > Just my opinion.
I would welcome more natives to handle binary data. Many of my REBOL projects involve binary data files. One such program is a binary data dissector which takes a specification for structures in a data stream and dumps a text report of the stream. Another is a byte-code compiler which converts a REBOL dialect into a binary stream of instructions. In my experience dealing with binary data is a basic part of programming. I wish REBOL would provide a formal way to convert 32 & 64 bit IEEE floating-point values in binary data to/from number values. Using 'third make struct! [a [float]] [3.53]' just isn't elegant (not to mention slow), and is not portable between all versions of REBOL. Here are some functions I use which would be much faster as natives: ; Converts integer to 16 bit big-endian binary value. bin16: func [n] [ to-binary reduce [ to-integer n / 256 n and 255 ] ] bin16-le: func [n] [ to-binary reduce [ n and 255 to-integer n / 256 ] ] ; Converts integer to 32 bit big-endian binary value. bin32: func [n] [ load join "#{" [form to-hex n "}"] ] bin32-le: func [n /local data a b c d] [ data: form to-hex n a: copy/part data 2 b: copy/part skip data 2 2 c: copy/part skip data 4 2 d: copy/part skip data 6 2 load join "#{" [d c b a "}"] ] swap16: func [data] [ data/1 + (data/2 * 256) ] swap32: func [data] [ data/1 + (data/2 * 256) + (data/3 * 65536) + (data/4 * 16777216) ] -Karl Robillard

 [7/9] from: dockimbel:free at: 15-Aug-2003 3:36


Karl Robillard wrote: [...]
> Here are some functions I use which would be much faster as natives: > ; Converts integer to 16 bit big-endian binary value.
<<quoted lines omitted: 19>>
> swap32: func [data] [ data/1 + (data/2 * 256) + (data/3 * 65536) + > (data/4 * 16777216) ]
Until RT releases the plugin API so you'll be able to code them in C directly, here's a faster implementation of these functions : bin16: func [n][at debase/base to-hex n 16 3] bin16-le: func [n][copy/part head reverse debase/base to-hex n 16 2] bin32: func [n][debase/base to-hex n 16] bin32-le: func [n][head reverse debase/base to-hex n 16] swap16: swap32: func [data][to integer! head reverse data] HTH, -DocKimbel

 [8/9] from: tim:johnsons-web at: 14-Aug-2003 18:38


* Nenad Rakocevic <[dockimbel--free--fr]> [030814 17:56]: <... snip ...> > (data/4 * 16777216) ]
> Until RT releases the plugin API so you'll be able to code them in C directly, > here's a faster implementation of these functions :
??? I've been out of the loop for a while. Any more details on the "plugin API"? URL for Docs? thnx tj
> bin16: func [n][at debase/base to-hex n 16 3] > bin16-le: func [n][copy/part head reverse debase/base to-hex n 16 2]
<<quoted lines omitted: 6>>
> To unsubscribe from this list, just send an email to > [rebol-request--rebol--com] with unsubscribe as the subject.
-- Tim Johnson <[tim--johnsons-web--com]> http://www.alaska-internet-solutions.com http://www.johnsons-web.com

 [9/9] from: krobillard:cox at: 14-Aug-2003 22:19


On Thursday 14 August 2003 06:36 pm, you wrote:
> Until RT releases the plugin API so you'll be able to code them in C > directly, here's a faster implementation of these functions :
<<quoted lines omitted: 5>>
> HTH, > -DocKimbel
Thanks for improvments Nenad. Swap16/32 need a copy/part 2 or copy/part 4 for the way I use them, but this is much better. Your bin16 is twice as fast and bin32 is six times faster. I seem to recall playing with debase but I can't remember why I didn't use it. -Karl

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted