splitting 16bit to 2 x 8bit
how would i split a 16bit value to two 8 bit values which i can store and than reconvert those 2 8bit values into the 16bit value...
in VC++ you can use HIBYTE or LOBYTE to extract the values (or use bit masks to construct equivalent macros). you can also just store the two values independently as char's.
The only real way to do it mathematically is to use ints, mod, and divide.
High byte: value/256
Low byte: value%256
As long as you're using integer values, that should do what you want.
High byte: value/256
Low byte: value%256
As long as you're using integer values, that should do what you want.
yes it is....
so would it be like this then?
so would it be like this then?
unsigned short _16bit;unsigned char _8bitLOW, _8bitHIGH;_8bitLOW= _16bit | pow(2,8);_8bitHIGH = _16bit | (pow(2,16)-pow(2,8));
Quote:Original post by Merlz
The only real way to do it mathematically is to use ints, mod, and divide.
High byte: value/256
Low byte: value%256
As long as you're using integer values, that should do what you want.
didnt see that.. ill try it out
EDIT:: how do i get back to the original value?
union Value {
unsigned short _16bit;
unsigned char _8bit[2];
};
With this you can access the 16 bit value or the two 8 bit values when ever you want without converting or reconverting anything =)
unsigned short _16bit;
unsigned char _8bit[2];
};
With this you can access the 16 bit value or the two 8 bit values when ever you want without converting or reconverting anything =)
Quote:Original post by Dragon_Strike
how do i get back to the original value?
To get the original 16-bit value from two 8 bit values, you would do this:
(highByte*256)+lowByte
You are unbelivable.
byte A = (byte) (TheShort >>> 8);
byte B = (byte) (TheShort & 0xFF);
short TheShort = (A << 8) | B;
Now lets look at a paper about pixel shaders.
http://64.233.183.104/search?q=cache:2rpIwdgSvKYJ:graphics.cs.uiuc.edu/~jch/papers/pixelnoise.pdf+pixel+shader+bit+shifting&hl=en&ct=clnk&cd=3
It looks like it describes all what is necessary for the above in a pixel shader.
byte A = (byte) (TheShort >>> 8);
byte B = (byte) (TheShort & 0xFF);
short TheShort = (A << 8) | B;
Now lets look at a paper about pixel shaders.
http://64.233.183.104/search?q=cache:2rpIwdgSvKYJ:graphics.cs.uiuc.edu/~jch/papers/pixelnoise.pdf+pixel+shader+bit+shifting&hl=en&ct=clnk&cd=3
It looks like it describes all what is necessary for the above in a pixel shader.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement