473,405 Members | 2,154 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,405 software developers and data experts.

Declaring an array of bytes in c

We want to declare an array of 16 hexa decimal numbers of 8 bytes each.Like the following:

00000000_00000000
FFFFFFFF_FFFFFFFF
00000000_FFFFFFFF
0000FFFF_0000FFFF
00FF00FF_00FF00FF
0F0F0F0F_0F0F0F0F
33333333_33333333
55555555_55555555
AAAAAAAA_AAAAAAAA
CCCCCCCC_CCCCCCCC
F0F0F0F0_F0F0F0F0
FF00FF00_FF00FF00
FFFF0000_FFFF0000
FFFFFFFF_00000000
FFFFFFFF_FFFFFFFF
00000000_00000000

How can we achieve this in c?Any help is appreciated.

Thanks,
Namratha.
Jul 13 '07 #1
1 2277
weaknessforcats
9,208 Expert Mod 8TB
A hexadecimal digit requires 4 bits: F == 1111.

An unsigned integer is 32 bits, enough for 8 hex digits.
You number:

FFFFFFFF_FFFFFFFF


could be a struct variable:

Expand|Select|Wrap|Line Numbers
  1. struct Hex
  2. {
  3.    unsigned int left;            //big enough for FFFFFFFF
  4.    unsigned int right;          //big enough for FFFFFFFF
  5. };
  6.  
I would supply the underscore as part of the displayu of these numbers.

Now you can write functions using variables of this Hex struct:

Hex Add(Hex left, Hex right); //returns left + right).

Or, you could use a string:
Expand|Select|Wrap|Line Numbers
  1. char anumber[18] = "FFFFFFFF_FFFFFFFF";
  2.  
My preference would be to use the struct with two unsigned int members.

If you are using a 64 bit Unix system, a single unisgned int will do. However, if you ever need to port your code to 64-bit Windows, this approach won't work since 64-bit Windows has a 32-bit int. The 64-bit int is _int64. You might fudge this by using a macro:
Jul 13 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
22
by: Wynand Winterbach | last post by:
I think every C programmer can relate to the frustrations that malloc allocated arrays bring. In particular, I've always found the fact that the size of an array must be stored separately to be a...
3
by: mark | last post by:
When I declare an array as double(,) then try to use it I get an error: "Object reference not set to an instance of an object." I have found that I can redim the array and all is well. Is my...
12
by: gcary | last post by:
I am having trouble figuring out how to declare a pointer to an array of structures and initializing the pointer with a value. I've looked at older posts in this group, and tried a solution that...
11
by: rayreeves | last post by:
How do I declare an array of references to the elements of an array of values? Ray
8
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using vs2005, .net 2, C# for Windows application. I use DllImport so I can call up a function written in C++ as unmanaged code and compiled as a dll us vs2005. My application is able to...
2
by: O.B. | last post by:
When using Marshal to copy data from a byte array to the structure below, only the first byte of the "other" array is getting copied from the original byte array. What do I need to specify to get...
8
by: bintom | last post by:
What are the differences between the following methods of declaring strings? char string1 = "C++ forum"; char* string2 = "C++ forum"; I know that the first uses the array notation, whereas...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.