Hex Values - C
I have to write a C program which takes a 64bit hex number, splits it into its lower and higher halves and then converts them to binary.
my problem is for example
if the 64 bit hex number = [aa,bb,cc,dd,ee,ff,ab,ac]
which are the lower bits...does it start from [dd,cc,bb,aa] or is it from [aa,bb,cc,dd]. How should I read the hex values??
If anyone could clear this up for me I would greatly appreciate it.......
takes a million
It's a matter of protocol...how do you get input and display output for this program?
Personally, this way is most intuitive...
64 bit hex number = [aa,bb,cc,dd,ee,ff,ab,ac]
upper half = [aa,bb,cc,dd]
lower half = [ee,ff,ab,ac]
The hex values are coded into arrays.
But I thought Hex values were read left to right!!!!! and binary read right to left!!!
Like I said, it's a matter of protocol. Unless this is somehow hardware-related, I suggest that you do it so that the most significant digit is on the left.
Like QuestionC says, it's just matter of protocol. In other words, it's a matter of how you define which bit is on which place.
As I understand you have a 64 bit value. Let's define that the value is defined as follows (in bits):
b63 b62 ...... b1 b0
This can be grouped in bytes as follows:
B7 B6 ... B1 B0
Let us now define an array for storing the 64 bit value, where each byte is stored as a hexadecimal value:
hex_array = [H7, H6, H5, H4, H3, H2, H1, H0]
Where each hexadecimal value represents:
H7 = B7 = b63 b62 b61 b60 : b59 b58 b57 b56
H0 = B0 = b7 b6 b5 b4 : b3 b2 b1 b0
As you can see, I made some decisions about how to store the bits and this was the basis of defining the array. Keep in mind that you're storing a 64 bit value and not an array of independant 8-bit values.
So what you need to do is decide how to store the bits and and use this consequently in all the functions you're going to write with to manipulate the value. In essence, this was what QuestionC meant by protocol.