Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
It is currently Fri Dec 15, 2017 2:32 pm
xojo

All times are UTC - 5 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to convert the following code
PostPosted: Thu Aug 16, 2012 5:53 am 
Offline

Joined: Wed Feb 04, 2009 1:43 pm
Posts: 427
I asked this in another thread too but this may well be the correct place:

Found VB code to calculated the discid (for freedb).

Function DiscID() As Long
tocSum = 0
For Each track in CDTOC
tocSum = tocSum + AddDigits(track.PositionInSeconds)
Next

firstLastSum = CDTOC.track(0).PositionInSeconds
firstLastSum = firstLastSum - CDTOC.leadOut.PositionInSeconds

DiscId = ((tocSum and &HFF)>>24) Or ((firstLastSum)>>8) Or CDTOC.NumTracks
End Function

Function AddDigits(position)
addDigits = 0
Do While (position > 0)
addDigits = addDigits + (position Mod 10)
position = position \ 10
Loop
End Function



What does >> do? And how is it achieved with RB?


Top
 Profile  
Reply with quote  
 Post subject: Re: How to convert the following code
PostPosted: Thu Aug 16, 2012 11:03 am 
Offline

Joined: Mon May 30, 2011 12:56 am
Posts: 702
>> means 'shift the binary bits of the number to the right'
>> 24 means do it 24 times
>> 1 means do it once

So 0110 >>1 gives you 011 result.

((tocSum and &HFF)>>24) is evaluated as a boolean : (is the result anything other than 0?)


Top
 Profile  
Reply with quote  
 Post subject: Re: How to convert the following code
PostPosted: Thu Aug 16, 2012 12:29 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
Quote:
DiscId = ((tocSum and &HFF)>>24) Or ((firstLastSum)>>8) Or CDTOC.NumTracks

I don't think this is evaluating a boolean. I think it is doing a bitwise OR.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to convert the following code
PostPosted: Thu Aug 16, 2012 1:32 pm 
Offline

Joined: Wed Feb 04, 2009 1:43 pm
Posts: 427
timhare wrote:
Quote:
DiscId = ((tocSum and &HFF)>>24) Or ((firstLastSum)>>8) Or CDTOC.NumTracks

I don't think this is evaluating a boolean. I think it is doing a bitwise OR.


Ok, and how is this translated to RB?


Top
 Profile  
Reply with quote  
 Post subject: Re: How to convert the following code
PostPosted: Thu Aug 16, 2012 2:46 pm 
Offline
Real Software Engineer

Joined: Sat Dec 24, 2005 8:18 pm
Posts: 7858
Location: Canada, Alberta, Near Red Deer
well would be better to have the original C because this
(tocSum and &HFF)>>24

should always give you 0
it takes the lowest 8 bits (&hFF) and grabs those from tocSum (tocSum and &hFF) and shifts them right 24 bits - shifting 8 bits right 24 bits will give you 0 - always
So I suspect this is incorrect

the rest is pretty straight forward

dim tmpA as integer = (tocSum and &HFF)
tmpA = bitwise.ShiftRight( tmpA, 24)
dim tmpB as integer = bitwise.ShiftRight(firstLastSum,8)

DiscId = (tmpA Or tmpB) Or CDTOC.NumTracks

Its been a long time since I looked at CDDB disc ids

_________________
Norman Palardy (Real Software)


Top
 Profile  
Reply with quote  
 Post subject: Re: How to convert the following code
PostPosted: Sat Aug 18, 2012 1:10 pm 
Offline

Joined: Fri Jan 06, 2006 3:21 pm
Posts: 12388
Location: Portland, OR USA
According to Wikipedia, those ">>" operators should be "<<" - shift left.

Quote:
CDDB1 identifies CDs with a 32-bit number, usually displayed as a hexadecimal number containing 8 digits: XXYYYYZZ. The first two digits (labeled XX) represent a checksum based on the starting times of each track on the CD, mod 255. The next four digits (YYYY) represent the total time of the CD in seconds from the start of the first track to the end of the last track. The last two digits (ZZ) represent the number of tracks on the CD.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 5 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group