Acmlm's Board - I2 Archive - Programming - 4bpp routine
User | Post |
HyperLamer
Posts: 1844/8210 |
Originally posted by interdpth MyVar = Temp1 & Temp2 ?
You have to use 'And', not &.
In VB6, to combine a pair of 4-bit values into one 8-bit value, the simplest way is this:
Result = (HighValue * 16) + LowValue
However, if you haven't done any error-checking to make sure both values are <16, you'll want to use this:
Result = ((HighValue And 15) * 16) + (LowValue And 15)
Also when using operators like And and Or in If statments, brackets can change the whole expression. For example (a problem I actually had a while ago):
If (Value And (2 ^ Bit)) = 0 Then
This means 'if Value && (2 to the power of Bit) equals zero'. However, if we remove the brackets:
If Value And (2 ^ Bit) = 0 Then
It now means 'if Value doesn't equal zero, and (2 to the power of Bit) equals zero'. Any time you just do 'If Variable', VB assumes you mean 'If Variable <> 0' or 'If Variable = True'. (True = anything except 0 or the word 'false', so they're really the same statement.) |
dan
Posts: 206/782 |
Hah, I completely forgot about that when I made that post. |
sloat
Posts: 5/85 |
ByteVal = (HighNib * 16) Or LowNib
HighNib in this case would be 4 and LowNib would be 9.
&H4 * &H10 = &H40 &H40 Or &H9 = &H49
Unless I misunderstood what you were asking. |
dan
Posts: 205/782 |
That may not work in VB .NET, as I think it can be a git when it comes to automatically converting variables to different types. (well, from the VB perspective, it can be a git)
I think the Integer object has a method called ToString, so maybe something like:
MyVar = CType("&H" & temp1.ToString("x") & temp2.ToString("x"), Integer)
That might work. I really don't know though, as it was completely off the top of my head with a bit of googling for the type conversion function. |
interdpth
Posts: 342/527 |
MyVar = Temp1 & Temp2 ? |
elixirnova
Posts: 94/177 |
once again ill post this since nobody helped the other time. I progressed a bit......................But i figured out how to take the bytes from my palette value and somehow i have to store the first byte as 49 but stored in my 2 vars is temp1 = 4 temp2 = 9 i used the following code to do this a b c d w x y z are vars holding pixel colors 0 - 7 respectively temp1 = ((a And &H8) Or ((b And &H8) / 2) Or ((c And &H8) / 4) Or ((d And &H8) / 8)) * &H10 temp2 = (w And &H8) Or ((x And &H8) / 2) Or ((y And &H8) / 4) Or ((z And &H8) / 8)
So mainly my question is how do i take two numbers 0-F and make them one btw: 49 in binary = 0011 0001 ---4 in binary = 0100-----9 in binary = 1001 |
|