469,917 Members | 1,474 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

Hexadecimal index array

Hi,

I am handling an array with a hexadecimal index for the first time.
What actually does the below means.

arr[0x80] = { '@','','$','@','@','@','@','@','@','@', 10,'@', 13,'@','@','@',
'@','_','@','@','@','@','@','@','@','@','@', 32,'@','@','@','@',
' ','!','"','#','@','%','&', 39,'(',')','*','+',',','-','.','/',
'0','1','2','3','4','5','6','7','8','9',':',';','< ','=','>','?',
'@','A','B','C','D','E','F','G','H','I','J','K','L ','M','N','O',
'P','Q','R','S','T','U','V','W','X','Y','Z','@','@ ','@','@','@',
'@','a','b','c','d','e','f','g','h','i','j','k','l ','m','n','o',
'p','q','r','s','t','u','v','w','x','y','z','@','@ ','@','@','@'};

what does an index 0x80 means n why can not one write 128 instead of 0x80?

Anjali.
Nov 14 '05 #1
6 3099
On 11 Apr 2005 21:40:47 -0700, as*********@gmail.com (Anjali) wrote in
comp.lang.c:
Hi,

I am handling an array with a hexadecimal index for the first time.
What actually does the below means.

arr[0x80] = { '@','','$','@','@','@','@','@','@','@', 10,'@', 13,'@','@','@',
'@','_','@','@','@','@','@','@','@','@','@', 32,'@','@','@','@',
' ','!','"','#','@','%','&', 39,'(',')','*','+',',','-','.','/',
'0','1','2','3','4','5','6','7','8','9',':',';','< ','=','>','?',
'@','A','B','C','D','E','F','G','H','I','J','K','L ','M','N','O',
'P','Q','R','S','T','U','V','W','X','Y','Z','@','@ ','@','@','@',
'@','a','b','c','d','e','f','g','h','i','j','k','l ','m','n','o',
'p','q','r','s','t','u','v','w','x','y','z','@','@ ','@','@','@'};

what does an index 0x80 means n why can not one write 128 instead of 0x80?

Anjali.


0x80 in a C program is a numeric literal of type int with a value of
128. One could write 128 instead of 0x80, or even 0200, which is a
numeric literal in octal that has the same value.

As for why the person writing the code used 0x80 instead of 128, one
can only guess. The two likeliest possibilities that come to my mind
are that he/she was showing off, of that he/she was making a point
that might make sense if one saw the rest of the source code.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
as*********@gmail.com (Anjali) writes:
I am handling an array with a hexadecimal index for the first time.
What actually does the below means.

arr[0x80] = { '@','#','$','@','@','@','@','@','@','@', 10,'@', 13,'@','@','@',
You should know that #, $, and @ are not portably available for
use in C source.

[...]
what does an index 0x80 means n why can not one write 128 instead of 0x80?


128 and 0x80 have the same type and value. You can write 128
instead of 0x80 if you want. I would tend to prefer 0x80 if I
wanted to refer to a bit pattern instead of a count, but either
one is acceptable.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #3
In article <e0**************************@posting.google.com >,
Anjali <as*********@gmail.com> wrote:
I am handling an array with a hexadecimal index for the first time.
What actually does the below means. what does an index 0x80 means n why can not one write 128 instead of 0x80?


As you gathered, the size of 0x80 means the same thing as 128.

As to -why- the programmer chose 0x80, it's probably because
they were defining an array whose contents were fundamentally linked
to binary numbers.

If you examine the table, you will see that it is exactly 8
rows of 16 positions each. 16 is 0x10, so 8 of those is 0x80.
And the entries are some kind of translation table that maps
ascii characters to something: if you examine a table of ascii
you will see that most of the positions in the array hold the
ascii character that would appear in an ascii table at the
corresponding position. ascii defines meaning and representations
to exactly 7 bits worth of characters, so the number of positions
it defines is 2 to the 7th, which is 0x80.

The size of the ascii table is not "Oh, it happens to be 128
this time, but next time around maybe we'd chose 126 or 131":
the size of the ascii table is determined by *binary* arithmetic,
not decimal arithmetic.. and 0x80 as the size serves to emphasize
that it is a binary table size involved, not a decimal size
that just happens to be somewhat close to an important binary number.

--
Are we *there* yet??
Nov 14 '05 #4
In article <87************@benpfaff.org>,
Ben Pfaff <bl*@cs.stanford.edu> wrote:
as*********@gmail.com (Anjali) writes:
I am handling an array with a hexadecimal index for the first time.
What actually does the below means. arr[0x80] = { '@','#','$','@','@','@','@','@','@','@', 10,'@', 13,'@','@','@',

You should know that #, $, and @ are not portably available for
use in C source.


Hmmm, what's the trigram version of #if again?

When my newsreader examines the original message or anyone's quote
of it except for yours, I see a pound-sign in the second array
position; in your version and your text, I see an octathorpe
(also known as a "number sign.")
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Nov 14 '05 #5
Walter Roberson wrote:
Ben Pfaff <bl*@cs.stanford.edu> wrote:
...
You should know that #, $, and @ are not portably available for
use in C source.


Hmmm, what's the trigram version of #if again?


ITYM trigraph, but purely for the record, it's ??=if

--
Peter

Nov 14 '05 #6
ro******@ibd.nrc-cnrc.gc.ca (Walter Roberson) writes:
When my newsreader examines the original message or anyone's quote
of it except for yours, I see a pound-sign in the second array
position; in your version and your text, I see an octathorpe
(also known as a "number sign.")


I see the same thing. I don't know what happened; when I pushed
"post", there was a British pound sign in my editor window, and
it must have gone through translation subsequently somehow.
--
Ben Pfaff
email: bl*@cs.stanford.edu
web: http://benpfaff.org
Nov 14 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Joel Moore | last post: by
8 posts views Thread by Vijay | last post: by
7 posts views Thread by elliotng.ee | last post: by
14 posts views Thread by abhishekkarnik | last post: by
6 posts views Thread by Andrea | last post: by
4 posts views Thread by sweeet_addiction16 | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.