Jump to content
  • Advertisement
Sign in to follow this  
Dragon_Strike

splitting 16bit to 2 x 8bit

This topic is 4222 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
yes it is....

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));


Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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 =)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!