# HTTP Tunnelling suggestions

This is a discussion on HTTP Tunnelling suggestions within the C Programming forums, part of the General Programming Boards category; Hello all. I am new here, but am hoping that someone may be able to help me with this one. ...

1. ## Comparing 16-bit integer values in C

Hello all.

I am new here, but am hoping that someone may be able to help me with this one. I've moved over to C from Java, am

following a few tutorials and have started learning about binary, hex and data manipulation.

One of the examples calls for a program that will identify a 16-bit number and report true if that number is 1.

So far I have:

Code:
```int bitident(int n, int b)
if(b == 000000000000001) {
n = 1 }
return n
else {
n = 0 }
return n```
but this seems to me to be too simple and vague. I'm not sure how to code into the 16-bit idea, as what is to stop anyone just putting in "1" and the program returning that as true?

I'm partially sighted and do find net navigation difficult at times, so if this has been posted and answered elsewhere on the board please forgive the discretion.

Your help would be verey much appreciated. I'm keen to understand and learn.

Thanks very much in advance.

Hussein - aka PCHolic.

2. The computer sees all data as binary, so comparing an int b to 000000000000001 is the same as comparing it to 1 or 0x1.

3. Code:
```int bitident(int b)
{
int n;

if(b == 1)
n = 1;
else
n = 0;
return (n);
}```
This should do what you want it to I think. C is a very low language in some respects, but in others it is not, and one of those others is that it is more complicated than you'd think to read a binary input, you need arrays and whatnot to do that. But what this will do, is it will take the input of int b and then compare it to one. If the value of b is equal to one, it will set n, a variable declared inside the function making it a local variable that will not work if you try to use it in any other place other than this function (unless you declare another variable n in that part of the code). If b is not equal to one n will be declared to equal zero. After it has assigned a value to n it returns that value as an integer to wherever you called the function. The way you had it before, it would return n after the if statement even if b wasn't equal to one. Also, because of that I believe that the code would not compile properly because the else statement would have another statement between it and the if statement which would cause the compiler to choke....I think.
Hope this helps
-Crazed

p.s. as you can see with the code I posted above it is indented to help with the readability. This both helps others understand your code and also helps yourself to realize if there is an error sometimes.

4. Hello and thanks for both of your replies.

Just so that I understand:

The computer reads everything at the lowest level as binary. Hex, octal etc are just shorthand version of binary, e.g 0x9C (h) instead of 10011101 (b), 157 (dec). So it makes no difference in the end.

just one point, using the example of the 157 (dec) above, would you have to hard code all the variations of that if you wanted to make a comparision, or would the program recognize 0x9C just as well as the long binary form?

Thanks also for the revised code. I can see now that it is just a simple comparison check. The tutorial question made it seem much more complicated with it's 16-bit integer format. Also, I can see now that indenting the various parts of the code makes it much easier to read. Thanks for that and I'll keep it in mind in the future.

I'll keep on learning and gathering knowledge, and will most likely be back soon.

Thanks much again, both of you. Sorry for the title of this thread, I'll see if I can rename it, the autocomplete must have run away with itself when I was creating the post.

Hussein. - aka PCHolic.

5. The C-compiler doesn't recognize any "long binary form".
the number
00000001 would be recognized as octal 1or 0x01 hex
00000010 would be octal 10 that translates to dec 8 or hex 0x08
Kurt

6. These two peices of code would compile to the exact same output
Code:
`if (b==157)`
Code:
`if (b==0x9D)`

7. Originally Posted by Quantum1024
These two peices of code would compile to the exact same output
Code:
`if (b==157)`
Code:
`if (b==0x9D)`
another one
Code:
`if (b==0235)`
Kurt

8. Of course, you can always play with the bits by using <<, >>, &, |, ~.

http://www.cs.cf.ac.uk/Dave/C/node13.html

9. Thanks I think I start to understand now how it works. Maths is not the love of my life but this I think I can cope with

Cheers.

Hussein.

Popular pages Recent additions