Advice on general approaches or feasibility and discussions about game design
by Valden » Thu Jul 09, 2015 4:18 pm
It's easy. Imagine 0b1111 1010 is your number. For selecting parts of the byte, you just have to use the "shift" operator. This operation moves the bits in the number left or right. So if I shift 4 bit to the right, the number will looks like this : 0b 0000 1111. In C, you use << for shifting bits to the left, and >> for shifting bits to the right. You have to do x >> y, wher x is your number and y the number of bits you what to shift.
So if you what to select the first part of the number, you do number >> 4.
The the second part (1010 in our case) you have to use a bit mask to 'mask' the first part. For that, you use the & (bit and) like this :
number & 0b0000 1111.
For more info check this :
https://en.wikipedia.org/wiki/Bitwise_operation#AND and
https://en.wikipedia.org/wiki/Bitwise_operation#Arithmetic_shiftTL;DR :
- Code: Select all
left_half = number >> 4;
//if it doesn't works, try left_half = (number >> 4) & 0b 0000 1111;
right_half = number & 0b0000 1111;
-
Valden
-
- Posts: 31
- Joined: Mon Jun 08, 2015 5:33 pm
by Marcus » Thu Jul 09, 2015 5:01 pm
awesome101 wrote:Hey guys I'm working on another console called pigrrl:
Very, very nice!
Who would have thought that it would be possible to build own consoles, manufacture plastic cases, easily program games when we where kids...
-
Marcus
-
- Posts: 143
- Joined: Fri Jan 09, 2015 6:51 pm
by adekto » Thu Jul 09, 2015 8:03 pm
wel its basicly a raspery pi running a emulator
but its prety nice
-
adekto
-
- Posts: 448
- Joined: Tue Feb 25, 2014 9:47 pm
- Location: belgium
by awesome101 » Thu Jul 09, 2015 10:02 pm
Yeah it's pretty easy to make too.
-
awesome101
-
- Posts: 159
- Joined: Sat Jun 20, 2015 6:56 pm
Return to Project Guidance & Game development
Who is online
Users browsing this forum: No registered users and 8 guests