Hex question

This is a discussion on Hex question within the Tech Board forums, part of the Community Boards category; I know this is probably a stupid question... x636F 6465 => Hex number Can I look at each number/letter individually ...

  1. #1
    Registered User
    Join Date
    Sep 2007
    Posts
    119

    Hex question

    I know this is probably a stupid question...

    x636F 6465 => Hex number

    Can I look at each number/letter individually and write the corresponding decimal value? Since F is the only value which won't be identical, can I just insert 15 (it's corresponding decimal value) and have the number in decimal form? I want to convert it into binary....

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Quote Originally Posted by John_L View Post
    I know this is probably a stupid question...
    Not stupid - but perhaps poorly phrased.

    x636F 6465 => Hex number

    Can I look at each number/letter individually and write the corresponding decimal value?
    You can do anything you want. What's your overall objective?

    Since F is the only value which won't be identical,...
    Huh? Not sure I understand this. If I follow your logic, why isn't the 3 also unique???

    ...can I just insert 15 (it's corresponding decimal value) and have the number in decimal form?
    Well, F is 15, if it's in the lowest nibble.

    I want to convert it into binary....
    Then all you need are bit patterns to replace the values. A little tight loop that spits out a 1 or a 0 based on the result of a BITWISE AND should work nicely. Test, output the 1 or 0, shift, repeat.

    Todd

  3. #3
    Registered User
    Join Date
    Sep 2007
    Posts
    119
    What about negative numbers if I were to use two's complement? -1 or -432 in hexadecimal form? I have the algorithm down for positive decimal numbers to hex and binary...not sure about the negative ones for hex though (binary is easy).

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    What do you care about negative numbers when converting from a base 16 representation of a base 2 number system?

  5. #5
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    Here's a way to convert a negative decimal number to a two-complement's hexadecimal representation
    Code:
     -1
    =   < take the absolute value of -1, which is 1 >
     1
    =   < transform it in hexadecimal >
     0x0001  (let's say we are working with 16-bits words)
    =   < negate (one complement or 15 complement if you are staying in base 16) >
     0xFFFE
    =   < add 1>
     0xFFFF
    Example with another number
    Code:
     -473
    =
     473
    =
     0x01D9
    =
     0xFE26
    =
     0xFE27

  6. #6
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,270
    Quote Originally Posted by John_L View Post
    I know this is probably a stupid question...

    x636F 6465 => Hex number

    Can I look at each number/letter individually and write the corresponding decimal value? Since F is the only value which won't be identical, can I just insert 15 (it's corresponding decimal value) and have the number in decimal form? I want to convert it into binary....
    What does decimal have to do with anything? Anyway, hex to binary is easy enough to do in your head: 636F6465 = 01100011011011110110010001100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Input a Hex number and output hex number to a text field
    By zoobaby in forum C++ Programming
    Replies: 4
    Last Post: 05-12-2009, 12:26 PM
  2. Displaying a whole file in hex
    By samus250 in forum C Programming
    Replies: 4
    Last Post: 06-30-2008, 04:31 PM
  3. Replies: 18
    Last Post: 03-26-2008, 10:01 AM
  4. Design layer question
    By mdoland in forum C# Programming
    Replies: 0
    Last Post: 10-19-2007, 05:22 AM
  5. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21