0x20 and such


 
Thread Tools Search this Thread
Top Forums Programming 0x20 and such
# 1  
Old 06-25-2007
0x20 and such

I'm looking at some code, and I'm seeing alot of things like 0x20, 0x60, 0x10, 0x0f, and 0x5f (just to name a few). I've seen really long ones, 0xb8000, and 0xc0000 to name two. What are these things called? I believe they are called 'bits'? How can I use them? Is this actually C, or does it something to do with assembly?

I might have more questions,
Octal.
# 2  
Old 06-25-2007
These are hex numbers. For example:
Code:
# cat test.c
#include<stdio.h>

int main(int argc, char *argv[]){
        int anInteger;
        anInteger=100;
        fprintf(stdout,"%x\n",anInteger);
}
# ./a.out 
64

This is 100 in decimal and printing it hex makes it 64 (hex).
Code:
# cat test.c
#include<stdio.h>

int main(int argc, char *argv[]){
        int anInteger;
        anInteger=0x100;
        fprintf(stdout,"%x\n",anInteger);
}
# ./a.out 
100

The above code specifies 100 in hex (using 0x). So printing it in hex just prints 100.
# 3  
Old 06-25-2007
By hex values, I assume you mean Hexadecimal? Being as 64 in hexadecimal is 100.

Once again, is there any way that I could use these to my advantage? I've these Hex values alot in kernels, one example being this tutorial. Is there a list of the values, and what the values do? If so, can you link me to it, or atleast give me something to search for. On google most of the results are related to HTML (hex colors).

Thanks,
Octal.
# 4  
Old 06-25-2007
Quote:
Originally Posted by Octal
Once again, is there any way that I could use these to my advantage?
C compilers let use use numbers represented in binary, octel, decimal and hexidecimal. But once the code is compiled they are all just bytes or combinations of bytes.

Hexidecimal representation is useful for bits and bitmasks where you want to make it obvious you are referring to one bit in a word, eg imagine a byte which is a series of flags and each bit has a different significance.

bit 0 = 0x01
bit 1 = 0x02
bit 2 = 0x04
bit 3 = 0x08
bit 4 = 0x10
bit 5 = 0x20
bit 6 = 0x40
bit 7 = 0x80
# 5  
Old 06-25-2007
Quote:
Originally Posted by porter
C compilers let use use numbers represented in binary, octel, decimal and hexidecimal. But once the code is compiled they are all just bytes or combinations of bytes.

Hexidecimal representation is useful for bits and bitmasks where you want to make it obvious you are referring to one bit in a word, eg imagine a byte which is a series of flags and each bit has a different significance.

bit 0 = 0x01
bit 1 = 0x02
bit 2 = 0x04
bit 3 = 0x08
bit 4 = 0x10
bit 5 = 0x20
bit 6 = 0x40
bit 7 = 0x80
Alright, let me see if I understand. These Hex Values can refer to a certain bit in a word, but how could I use this? Is there an operator (if so, I'm assuming a bitwise) that would declare that certain bit?

Or maybe not? I know that the bit 7 in there is the 'case bit', which can turn on/off weather the character is capital. So I'm assuming you can use other bits in this fashion?

I believe the latter is correct; please tell me if it's not.

Thanks,
Octal.
# 6  
Old 06-25-2007
Quote:
Originally Posted by Octal
Or maybe not? I know that the bit 7 in there is the 'case bit', which can turn on/off weather the character is capital. So I'm assuming you can use other bits in this fashion?
Not quite,

In Ascii, the lower case are 'a' to 'z', which are 0x61 to 0x7A, and upper case are 0x41 to 0x5A, so you could treat bit 6 as a case bit if the character falls in this range, but this falls down when you add diacriticals.

There are the the << and >> operators, which will shift a value left or right a number of bits. Hence (x)<<7 would convert 0x01 to 0x40 for example.

Note that the least significant bit is consider "bit zero", and has a value of 1. If you set "bit one", you would have a value of two.
# 7  
Old 06-25-2007
Does anyone have a tutorial on these? I've been fooling around with them and trying to see what they do to diffrent characters, but reading a tutorial would be much more efficient then conducting my own experiment.
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question