Thread: Hex Values - C

  1. #1
    Registered User
    Join Date
    Jan 2002
    Posts
    2

    Unhappy Hex Values - C

    hi,
    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
    Dee

  2. #2
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    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]
    Callou collei we'll code the way
    Of prime numbers and pings!

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    2
    The hex values are coded into arrays.

    eg:array=[aa,bb,cc,dd,ab,ac,ad,ae]

    But I thought Hex values were read left to right!!!!! and binary read right to left!!!

  4. #4
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    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.
    Callou collei we'll code the way
    Of prime numbers and pings!

  5. #5
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. putting values into an array
    By zdream8 in forum C Programming
    Replies: 15
    Last Post: 05-21-2008, 11:18 PM
  2. Need help with project
    By chrisa777 in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2006, 05:01 PM
  3. adding ASCII values
    By watshamacalit in forum C Programming
    Replies: 1
    Last Post: 12-26-2002, 07:16 PM
  4. How to read in empty values into array from input file
    By wpr101 in forum C++ Programming
    Replies: 5
    Last Post: 11-28-2002, 10:59 PM
  5. Replies: 1
    Last Post: 04-05-2002, 11:19 AM