Hexadecimal index array

A

Anjali

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.
 
B

Ben Pfaff

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.
 
J

Jack Klein

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.
 
W

Walter Roberson

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.
 
W

Walter Roberson

(e-mail address removed) (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.")
 
B

Ben Pfaff

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top