# Real Software Forums

The forum for Real Studio and other Real Software products.
[ REAL Software Website | Board Index ]
 It is currently Sat Jun 23, 2018 2:45 pm

 All times are UTC - 5 hours

 Page 1 of 1 [ 6 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: How to convert the following codePosted: Thu Aug 16, 2012 5:53 am

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:

`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.NumTracksEnd FunctionFunction AddDigits(position)  addDigits = 0  Do While (position > 0)    addDigits = addDigits + (position Mod 10)    position = position \ 10  LoopEnd Function`

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

Top

 Post subject: Re: How to convert the following codePosted: Thu Aug 16, 2012 11:03 am

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

 Post subject: Re: How to convert the following codePosted: Thu Aug 16, 2012 12:29 pm

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

 Post subject: Re: How to convert the following codePosted: Thu Aug 16, 2012 1:32 pm

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

 Post subject: Re: How to convert the following codePosted: Thu Aug 16, 2012 2:46 pm
 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

 Post subject: Re: How to convert the following codePosted: Sat Aug 18, 2012 1:10 pm

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

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 6 posts ]

 All times are UTC - 5 hours

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

Search for:
 Jump to:  Select a forum ------------------ General    General    Getting Started    Networking    Databases    Visual Basic to REAL Studio Conversion    Games    Plugins    Tips    Web Control SDK Platform Specific    Windows    Macintosh    Linux    Web Other Topics    Announcements    Off-Topic    Third Party Add-ons