473,399 Members | 3,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

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 3602
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Joel Moore | last post by:
Maybe I'm just easily baffled after an all-nighter but I can't seem to figure out how to represent a BitArray as a hexadecimal string. For example: Dim outputBank As New BitArray(8) ...
2
by: Henry | last post by:
Hi, I have a Byte array that holds hexadecimal values (ASCII e.g. byte value is hex 54 for the letter T). Dim bytes() As Byte = New Byte(size) {} ..... get the bytes array
8
by: Vijay | last post by:
Hi , I am doing a small project in c. I have a Hexadecimal file and want to convert into ascii value. (i.e., Hexadecimal to Ascii conversion from a file). Could anyone help me? Thanks in...
14
by: dharmdeep | last post by:
Hi friends, I need a sample code in C which will convert a Hexadecimal number into decimal number. I had written a code for that but it was too long, I need a small code, so request u all to...
7
by: elliotng.ee | last post by:
I have a text file that contains a header 32-bit binary. For example, the text file could be: %%This is the input text %%test.txt Date: Tue Dec 26 14:03:35 2006...
14
by: abhishekkarnik | last post by:
Hi, I am trying to read an exe file and print it out character by character in hexadecimal format. The file goes something like this in hexadecimal 0x4d 0x5a 0x90 0x00 0x03 .... so on When I...
0
by: Onecarb | last post by:
Hi, i need help for a (maybe) simple function :). I need to send by serial port a series of hexadecimal bytes with a xor control character. The language i use could not work with hexadecimal and...
6
by: Andrea | last post by:
Hi, suppose that I have a string that is an hexadecimal number, in order to print this string I have to do: void print_hex(unsigned char *bs, unsigned int n){ int i; for (i=0;i<n;i++){...
4
by: sweeet_addiction16 | last post by:
i have to write these hexadecimal values into a file(say using fwrite) in c.. 4d 54 68 64 00 00 00 06 00 00 00 01 00 80 4d 54 72 6b 00 00 00 8c 00 ff 58 04 04 02 30 08 00 ff 59 02 00 00 00 90...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.