hex 16's compliment

This is a discussion on hex 16's compliment within the Tech Board forums, part of the Community Boards category; is this a valid formula? and is this calculation correct? decimal 15 hex value "F" ((10h+F)-1h)+1h 1F...

  1. #1
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589

    hex 16's compliment

    is this a valid formula?
    and is this calculation correct?

    decimal 15
    hex value "F"

    ((10h+F)-1h)+1h
    1F
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    I have never even heard of a "hex 16's compliment"

    I have heard about 1's and 2's compliment

    What are you trying to do?

  3. #3

    Join Date
    May 2005
    Posts
    1,041
    I thought to convert to hex 16's complement you still just reverse the bits and add 1, but to reverse the bits you just subtract the number from 15.
    I'm not immature, I'm refined in the opposite direction.

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Ok so he's just trying to do two's complement without converting first.

    yeah it'd (for numbers between 0 and 15):
    (F-x)+1

    ((10h+F)-1h)+1h
    1F
    Expand what you wrote out and you are left with: 10h+F as -1 and +1 produce 0

  5. #5

    Join Date
    May 2005
    Posts
    1,041
    Sounds correct to me thantos.
    I'm not immature, I'm refined in the opposite direction.

  6. #6
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    here is the exact question.
    Will taking the two's complement of a binary number and then converting to hex result in the same hex number as converting the original number to hex and taking its 16's complement?
    The book doesn't disclose the 16's compliment
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  7. #7

    Join Date
    May 2005
    Posts
    1,041
    I think you need to work that out for yourself, you should have enough knowledge to work some examples out on paper (or, perform a thought experiment).

    If you want to have us check your work I think that will be acceptable but is against policy on the boards to just give an answer directly (sorry).


    step1:
    take the binary number 15:

    0000 1111

    flip its bits, add 1, then convert it to hex

    step2:
    take the binary number 15:
    0000 1111

    convert it to hex

    once you have the hex, subtract it from 15, add 1, then compare the results to step1.

    show us each step.
    Last edited by BobMcGee123; 09-13-2005 at 04:31 PM.
    I'm not immature, I'm refined in the opposite direction.

  8. #8
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    against policy on the boards to just give an answer directly (sorry).
    thanks for your insight.
    I'm not trying to get a free answer. I need more direction for my research.
    I was asking a question, and thantos requested the exact details that initiated my post.
    Anyway, the reason for the post was to clarify the 16's compliment.
    That is why my original post asked for insight on how to correct my understanding of the convertion algarithm.

    Thantos, thank you for your constructive comments.

    one more request for clarification.

    Please anyone with constructive comments tell me if i'm off on this.

    Code:
    n = total bits used
    B = radix/base
    ([(B^n)] - OriginalValue) = B^nCompliment
     
    10101100b = 172d
    01010011b = 83d// Flipped
    +1b// Add 1
    -------------
    01010100b = 84d // 2's Compliment
     
    10101100b = 172d = ACh
    11111111b = 255d = FFh
     
    (FFh - ACh) + 1h = 54h = 84d = 01010100b
    Last edited by xviddivxoggmp3; 09-13-2005 at 11:50 PM.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

  9. #9
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  10. #10
    essence of digital xddxogm3's Avatar
    Join Date
    Sep 2003
    Posts
    589
    Dave,
    Thanks for the info.
    I figured out what i was doing wrong.
    I have it perfect now.
    That site helped.
    I wasn't sure of what subjects to search for.
    So it helped.
    "Hence to fight and conquer in all your battles is not supreme excellence;
    supreme excellence consists in breaking the enemy's resistance without fighting."
    Art of War Sun Tzu

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Ascii to hex and hex to Ascii
    By beon in forum C Programming
    Replies: 1
    Last Post: 12-26-2006, 05:37 AM
  2. Hex Editing help and information please...
    By SG57 in forum C Programming
    Replies: 9
    Last Post: 06-25-2006, 12:30 AM
  3. Replies: 11
    Last Post: 03-24-2006, 10:26 AM
  4. Replies: 3
    Last Post: 01-23-2006, 06:25 PM
  5. Is binary HEX?
    By Budgiekarl in forum Tech Board
    Replies: 11
    Last Post: 11-23-2003, 08:02 AM

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