Help rewriting a C function in RB 
Author Message
 Help rewriting a C function in RB

Quote:

> I have a bit a code written in C that I would like to convert and use
> in an RB app. Can someone translate C for me? I don't speak it. TIA.

>    hash = __rlwinm(hash, 3, 0, 31) ^ tolower(inString[i]);

maybe this:

hash= bitwisenot(__rlwinm(hash, 3, 0, 31),
asc(lowercase(mid(inString,i,1))))

Mfg
Christian

--
Wer f?hig ist S?tze zu tippen, der ist auch f?hig Schreibfehler zu
machen.
[WoKo in dag]
http://www.*-*-*.com/ (Kostenlose Mac/Win Software)



Thu, 09 Dec 2004 19:56:03 GMT  
 Help rewriting a C function in RB

Quote:

> 1. What does the double underscore do?

The function is not quite a public one.

Quote:
> 2. I haven't yet found a good explanation/simple example of the rlwinm
> function.

Some kind of special function from a lib.

Quote:
> 3. The ^ is a bitwise exclusive OR. How is that different from a
> regular bitwise OR?

     0001010101
     0101101111
OR:  0101111111
XOR: 0100111010

See it?
OR sets a bit, if one or two bits above are set.
XOR sets a bit if only a bit, if both above are different.

Mfg
Christian

--
Wenn ueber irgend eine dumme Sache Gras gewachsen ist,
kommt bestimmt ein Kamel an und frisst es wieder weg.
http://www.christians-software.de (Kostenlose Mac/Win Software)



Fri, 10 Dec 2004 23:38:12 GMT  
 Help rewriting a C function in RB

Quote:

> 2. I haven't yet found a good explanation/simple example of the rlwinm
> function.

Isn't rlwinm a PowerPC mnemonic?

--

"Life. Don't talk to me about life." - Marvin, the android



Sat, 11 Dec 2004 22:47:08 GMT  
 Help rewriting a C function in RB


Quote:
> rlwinm

rlwinm (Rotate Left Word Immediate then AND with Mask) Instruction


Sat, 11 Dec 2004 23:31:18 GMT  
 Help rewriting a C function in RB

Quote:


> > 2. I haven't yet found a good explanation/simple example of the rlwinm
> > function.

> Isn't rlwinm a PowerPC mnemonic?

Flowing up on my own post...

Logical Shift Left And Mask. It is a PPC opcode that has a lot of bang
for the buck.

result = __rlwinm(hash, 3, 0, 31)
                   |    |  |   |
                   |    |  |   +--- Mask value start
                   |    |  +------- Mask value end
                   |    +---------- Number of places to shift
                   +--------------- Source value

See the PowerPC referance manual for an explaniation of how to generate
the mask value.

You need Mr. Tempelmann's BitOps plug in (http://www.tempel.org/rb/) in
order to accomplish the shifting. A pure RB rewrite would be something
like:

DIM HashThis as String
DIM temp1, temp2, temp3, HashResult as integer

HashThis = "Some String"
HashResult = lenb(HashThis) + 1

for i = 1 to len(HashThis)
 temp1 = asc(lowercase(midb(HashThis,i,1)))
 temp2 = LogicalShift(HashResult, -3)        // -3 is left three places
 temp3 = BitWiseAnd( temp2, &hffffffff )     // This is a non operation
 HashResult = BitwiseXor( temp3, temp1 )
next

// HashResult contains the hash value
// Note: the code above is untested

--

"Life. Don't talk to me about life." - Marvin, the android



Sun, 12 Dec 2004 00:03:48 GMT  
 Help rewriting a C function in RB

Quote:



> > rlwinm

> rlwinm (Rotate Left Word Immediate then AND with Mask) Instruction

Oops. You are right. My other post shifted the value bits rather than
rotating the bits. Other than that little detail, it should be OK.

:)

--

"Life. Don't talk to me about life." - Marvin, the android



Sun, 12 Dec 2004 00:10:41 GMT  
 
 [ 6 post ] 

 Relevant Pages 

1. Rewrite interface for the RB?

2. Rewriting data using REWRITE ?

3. (Follow up) Rewriting Clipper Tools functions

4. Rewriting Clipper Tools functions

5. to CS: or not to CS: in F-PC assembler

6. HELP: Intro book on Rewriting Systems

7. HELP: AXP Cobol version 2.1problem with REWRITE....

8. Newbie: Help w/ WRITE, REWRITE and DELETE statements.

9. Dragon Macros (was: RE: Help Rewriting/Refactoring/Rethinking Parsing Algorythm)

10. Help Rewriting/Refactoring/Rethinking Parsing Algorythm

11. 0.6 Rewrite Under Way -- Want to Help?

12. Ord Function HELP Please HELP HELP HELP

 

 
Powered by phpBB® Forum Software