Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Bitshift Visual C++ and DB Pro

Author
Message
mahoon
17
Years of Service
User Offline
Joined: 25th Sep 2008
Location:
Posted: 16th Nov 2009 22:44
Now, I don't pretend to understand this stuff, hence my request for help, but I'm trying to translate a (not terribly well written, I'm reliably informed) Visual C++ example into something I can use in DBPro

parts of the VC++ code include:

BYTE Byte[40];
Byte[0]=0;

I'm hoping the DB equivalent is:

dim bytes (40) as byte
bytes(0)=0


the next bit of VC++:
ax = Byte[0]+((Byte[1]&0x7f)<<8)

which, I hope, can be written in DBPro as:

ax= bytes(0)+((bytes(1)&&0x7f) << 8)

I wrote this little prog to just test if that syntax would at least compile. It did:

dim bytes (40) as byte

bytes(0)=0x14
bytes(1)=0x20
bytes(15)=0x0a


ax= bytes(0)+((bytes(1)&&0x7f) << 8)

for t=0 to 19
print bytes(t)
next t

print ax

wait key
end


the
bytes(0)=0x14
bytes(1)=0x20
bytes(15)=0x0a


have no significance whatsoever, I was just testing things.
The results of that prog are:

20
32
0
0
0
0
0
0
0
0
0
0
0
0
0
10
0
0
0
0
8212

Can anyone who know these things tell me if that's what I should be seeing? I feel that last number looks a little out of place and suspect it's either the && or the way I've bracketed things...
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 16th Nov 2009 23:51
From the code you've given, the C and DBPro code are equivalent.

Basically, take array entry 1, mask off the high bit (which has no effect on the number 0x20), shift it left 8 bits (equivalent to multiply by 256, giving a result of 0x2000), then add array entry 0 to it togive a result of 0x2014, which is equivalent to 8212 decimal.

mahoon
17
Years of Service
User Offline
Joined: 25th Sep 2008
Location:
Posted: 17th Nov 2009 10:00
Thanks so much for that Ian.

Am only just beginning to understand this bitshift malarky but very pleased that bit o' code is doing what it should.
Thanks again.
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Nov 2009 19:31
Quote: "From the code you've given, the C and DBPro code are equivalent."


Are they? I thought the C++ declaration



declared an array with 40 elements numbered from 0 to 39, whereas the DBPro declaration



declared an array with 41 elements numbered from 0 to 40. Of course, the snippets are functionally the same in this case since the 41st element isn't accessed in either version.

Or have I got confused with arrays in HLSL ...
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Nov 2009 20:40
No, you are correct, but it doesn't make too much difference in any event.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 17th Nov 2009 21:04
Indeed.

Login to post a reply

Server time is: 2026-06-12 12:35:49
Your offset time is: 2026-06-12 12:35:49