0

hi i'm working on a personal project for a transport parser.

i want to be able to represent a recived packet in binary number and afterwards be able to set specific bits. I've got a pretty good idea how to do the second part but i'm really stuck at the beginning ive got an advice to use unsigned char for that but can i really represent a full packet in that variable.

thanks

2 Answers 2

1

an unsigned char array is probably what you need: you can store whatever you want in this structure and access it in whatever means pleases you.

You could have this container in a bigger container too: the bigger container would have pointers to the each layer's beginning & end etc.

Sign up to request clarification or add additional context in comments.

1 Comment

in C++ I'd recommend using std::vector<unsigned char>. For OP, just look at 'arrays in C' in google..
0

I'd probably have a simple class (simple to begin with anyway):

class Packet
{
public:
 Packet(unsigned int length);
 Packet(void *data);
 bool getBit(unsigned int bit);
 void setBit(unsigned int bit,bool set);
private:
 std::vector<unsigned char> bytes;
};

That's just to start, no doubt it would get more complex depending what you use it for. You might consider overloading the array operator but that's probably outside "beginner level" and maybe best ignored right now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.