Quick Help Please ...
BlitzMax Forums/BlitzMax Programming/Quick Help Please ...| 
 | ||
| Hi, In desperate need of some help - could someone please rewrite the following C code in Blitzmax if ( data1 & 1<<c && data2 & 1<<c ) I'm struggling with the bit shifting in Blitzmax Thanks -Mic | 
| 
 | ||
| "Shl" is Shift Left. | 
| 
 | ||
| .. and & is & and && is And :) I'd use more parenthesis too, only because I'm strange like that. if ((data1 & (1 Shl c)) And (data2 & (1 Shl c))) | 
| 
 | ||
|  I'd use more parenthesis too  Me also. | 
| 
 | ||
| Hi, Thanks for this. This is what I'm trying to rewrite in it's entirety but I think I may not have it right yet as the output isn't what I expected ... C code 
for ( r = 0 ; r < 16 ; r+=2 ) {
	for ( c = 0 ; c < 8 ; c++ ) {
		if ( data[r] & 1<<c && data[r+1] & 1<<c ) vga_setcolor(2);
		else if ( data[r] & 1<<c && ! (data[r+1] & 1<<c) ) vga_setcolor(3);
		else if ( ! (data[r] & 1<<c) && data[r+1] & 1<<c ) vga_setcolor(4);
		else vga_setcolor(5);
		vga_drawpixel(x+(7-c),y+(r/2));
	}
}
Blitzmax 
For r = 0 To 15 Step 2
	For c = 0 To 7
		If (bit0 & (1 Shl c)) And (bit1 & (1 Shl c)) Then
			SetColor 196, 207, 161
		ElseIf (bit0 & 1 Shl c And Not (bit1 & 1 Shl c)) Then
			SetColor 139, 149, 109
		ElseIf (Not (bit0 & 1 Shl c) And bit1 & 1 Shl c) Then 
			SetColor 77, 83, 60
		Else
			SetColor 31, 31, 31
		EndIf
		DrawRect x+(7-c), y+(r/2), 1, 1
        Next
Next
Can anyone spot any obvious mistakes ? (Your help is greatly appreciated) Thanks -Mic | 
| 
 | ||
| For r = 0 To 15 Step 2
	bit0 = somedata[r]
	bit1 = somedata[r+1]
	For c = 0 To 7
		If (bit0 & (1 Shl c)) And (bit1 & (1 Shl c)) Then
			SetColor 196, 207, 161
		ElseIf (bit0 & 1 Shl c And Not (bit1 & 1 Shl c)) Then
			SetColor 139, 149, 109
		ElseIf (Not (bit0 & 1 Shl c) And bit1 & 1 Shl c) Then 
			SetColor 77, 83, 60
		Else
			SetColor 31, 31, 31
		EndIf
		DrawRect x+(7-c), y+(r/2), 1, 1
        Next
Next
 | 
| 
 | ||
| Hi Sorry Zeke, I removed the two lines you've added from the pasted code to make it easier to read - they are in the actual code :-) -Mic | 
| 
 | ||
| but in your code you say bit0 and bit1... and in c code there is data[r] and data[r+1].. how do you set your bit0 and bit1? because they are bytes.. data[r]=first BYTE and data[r+1]=second byte.. no Bits... | 
| 
 | ||
| Full code for clarity For r = 0 To 15 Step 2 SeekStream(bufferStream, r) Local bit0:Byte = ReadByte(bufferStream) Local bit1:Byte = ReadByte(bufferStream) For c = 0 To 7 If (bit0 & (1 Shl c)) And (bit1 & (1 Shl c)) Then SetColor 31, 31, 31 ElseIf (bit0 & 1 Shl c And Not (bit1 & 1 Shl c)) Then SetColor 77, 83, 60 ElseIf (Not (bit0 & 1 Shl c) And bit1 & 1 Shl c) Then SetColor 139, 149, 109 Else SetColor 196, 207, 161 EndIf DrawRect (x+(7-c))*4, (y+(r/2))*4, 4, 4 Next Next | 
| 
 | ||
| Are you actually working with bits when you use bit0 and bit1?  They should probably be bytes. Parenthesis look screwy too. I'd be happy with the first If (by "happy", I mean "confident I could predict its output") but not with the EsleIF's. | 
| 
 | ||
| SeekStream(bufferStream, r) is your bad.. you are always reading from start of stream.. (r=0 to 15) then when x/y changes then again First bytes of stream) just remove seekstream and test again... |