I am trying to check the input for 8 bit an unsigned integer is this the right why to go about it?
struct int8bit
{
unsigned int number : 8;
}
.

Recommended Answers

All 5 Replies

No.
Use an if statement.

how can i do that?

I am trying to check the input for 8 bit an unsigned integer.

I don't understand what you are trying to do. What are you checking?

if ( x >= 0 && x <= 255 )
x will fit in an unsigned 8 bits

yeah, I think the only way to check is the value. Since an unsigned 8 bits integer (or unsigned char) can only store (0 to 255). The best way is to check whether the value is between the range.

*make sure the memory for storing input is sufficient. After which you can do the range checking

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.