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.

Newcomers DBPro Corner / Befudled by Bytes

Author
Message
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 28th Sep 2008 21:29
Hi, first time posting on this forum and its because I\'m stumped by bytes.

I am teaching myself DarkBASIC Pro from the two huge books and I\'m up to space duel. In this they use bytes to record what keys have been pressed. However I don\'t understand how they work.

Could anyone possibly give me a concise explanation as to what bytes are, how you use them and why?

All help would be much apreciated.
calcyman
17
Years of Service
User Offline
Joined: 31st Aug 2007
Location: The Uncertainty Principle
Posted: 28th Sep 2008 22:44
A byte is a block of 8 bits (binary digits). They can have a value between 0 and 255. The following are bytes:

01111001 - 121
00000011 - 3
10000000 - 128

In DarkBASIC, you don't have to worry about the binary value, just the number. It behaves exactly like an integer, except it must be non-negative and has a much smaller range.

The advantage of bytes over integers is that they are 4 times smaller. A long line of bytes (known as a memblock) can be made in DBPro. The following is a memblock:

100,8,56,78,93,42,201,99,67,43

To access the values out of this use the memblock byte command:

a = memblock byte(1,0)
b = memblock byte(1,1)
c = memblock byte(1,2)

etc.

To put values into a memblock use the write memblock byte command:

write memblock byte 1,0,a
write memblock byte 1,1,b
write memblock byte 1,2,c

The optomist's right, The pessimist's right.
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 28th Sep 2008 22:53
TYVM for the help. Progress with space duel may now recommence
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 29th Sep 2008 10:03
But not for very long alas.

I have come to a piece of code in the program space duel which goes as follows:

If (KeysPressed && 1) > 0

Now as far as I understand it, you would ususually use %1 or %10 ect. However 1 is just a standard interger and further on in the program, both 2 and 4 are used in place of the one. KeysPressed is a byte.

So, could any kind soul explain to me what the above statement means? I understand that && would usually mean an exclusive AND but surely this cannot work without being in byte form...

Thanks for your help
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Sep 2008 16:06
%1 is just the binary representation of 1.
%10 is the binary representation of 2.

Basically, they mean the same thing - it's just that sometimes the binary representation is easier for you to read.

Login to post a reply

Server time is: 2024-11-24 19:53:25
Your offset time is: 2024-11-24 19:53:25