Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Decimal to Hexidecimal conversion...

  • 08-11-2006 12:35pm
    #1
    Closed Accounts Posts: 4,128 ✭✭✭


    ...and vice-versa.

    Can someone help me understand how it is done?

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    For Decimal to Hex, you divide by 16 and keep dividing until you can't divide any more, you store the remainders, they'll give you the hex number, read upwards to get the hex value.

    150 / 16 = 9 r 6
    9 / 16 = 0 r 9

    150 = 96h

    to do it the other way it each hex digit multiplied by 16^(pos of digit)

    9 * 16 (power of 1 ) + 6 * 16 (power of zero => 1 ) = 150


  • Closed Accounts Posts: 4,128 ✭✭✭dellas1979


    Thanks Silas........still over my head. Baby steps please!


  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    I'll assume you understand decimal to Hex, that easy just keep dividing the decimal number by 16, the hex number is all the remainders from each stage of the division.

    The other way is done like so
    take the hex number 2FF

    (2 * 16^2) + ( 15(F) * 16^1 ) + ( 15(F) * 16^0)
    (2 * 16^2) + (15 * 16) + (15 * 1)
    (512) + (240) + (15)
    767

    Thats it, there's nothing more to it. If it still goes over your head, try it out on a piece of paper, you'll soon get the hang of it.


  • Registered Users, Registered Users 2 Posts: 23,212 ✭✭✭✭Tom Dunne


    dellas1979 wrote:
    Thanks Silas........still over my head. Baby steps please!

    Start off by counting from zero to 15 (computers always count from zero, unlike humans).

    So, you have 0,1,2,3...9 when you get to nine, you then start using letters. It becomes ...8,9,A,B,C,D,E,F where A=10, B=11, C=12 and so on to F=15.

    Back to Decimal - what happens when you get to 9? You "reset" your counter and introduce a second digit. So 9 goes to 10. Likewise with Hex - when you get to F, you introduce another digit and reset the 'F' back to zero. So decimal 16 becomes Hex 10. You go ..E,F,10,11,12,13,14,15,16,17,18,19,1A,1B,1C... and so on.

    Does this help?


  • Closed Accounts Posts: 352 ✭✭yapyap


    silas wrote:
    For Decimal to Hex, you divide by 16 and keep dividing until you can't divide any more, you store the remainders, they'll give you the hex number, read upwards to get the hex value.

    150 / 16 = 9 r 6
    9 / 16 = 0 r 9

    150 = 96h

    to do it the other way it each hex digit multiplied by 16^(pos of digit)

    9 * 16 (power of 1 ) + 6 * 16 (power of zero => 1 ) = 150

    Let's say 1,000

    1000/16 = 62 r 8
    8/16 = 0 r 8

    (8*(16^1)) + (8*(16^0)) = 136

    by ure calculation 1000 = 88h --that doesn't sound right:confused::confused:


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,082 ✭✭✭Tobias Greeshman


    you don't divide by the remainder, it's the quotient

    so in your example

    1000 / 16 = 62 r 8
    62 / 16 = 3 r 14 (E)
    3 / 16 = 0 r 3

    reads as 3E8h which is 1000

    (3 * 16^2)+(14(E)*16^1)+(8*16^0)
    (3*256)+(14*16)+(8)
    768+224+8
    1000


  • Registered Users, Registered Users 2 Posts: 7,116 ✭✭✭Professional Griefer


    Really sorry to bump this but it just seemed easier than making a new one.

    I cannot understand this decimal to hex at all. I'm trying to convert 100 to hex. Each time I work it out I get 14, but I know the answer is 64, at least thats what the internet tells me.

    What I'm doing is 100/16 = 6 remainder 4
    4/16 = 0 remainder 4

    Its probably something stupid I'm doing, but its wrecking my head.

    Anyone help?


  • Registered Users, Registered Users 2 Posts: 25,705 ✭✭✭✭coylemj


    You put the first remainder on the right, continue to divide by 16 and each new remainder goes to it's left until you end up with a quotient less than 16 which counts as your last remainder since clearly you cannot divide any number less than 16 by 16 so the last quotient goes in front of the string of remainders.

    That is what happens on your first operation - decimal 100 divided by 16 = quotient 6 remainder 4 so the answer is Hex 64.

    Just to illustrate a more complex operation: convert decimal 498 to Hex.

    Divide 498 by 16 = quotient 31, remainder 2
    Divide 31 by 16 = quotient 1, remainder 15 (Hex F)

    So the final quotient (1) counts as a remainder since it cannot be divided by 16, it goes in front of the other two remainders and the answer is Hex 1F2


  • Registered Users, Registered Users 2 Posts: 7,116 ✭✭✭Professional Griefer


    Ah, I see now. Thank you so much.


  • Moderators, Computer Games Moderators Posts: 4,282 Mod ✭✭✭✭deconduo


    Really sorry to bump this but it just seemed easier than making a new one.

    I cannot understand this decimal to hex at all. I'm trying to convert 100 to hex. Each time I work it out I get 14, but I know the answer is 64, at least thats what the internet tells me.

    What I'm doing is 100/16 = 6 remainder 4
    4/16 = 0 remainder 4

    Its probably something stupid I'm doing, but its wrecking my head.

    Anyone help?

    You divide by the first number, not the remainder:

    100/16 = 6 remainder 4
    6/16 = 0 remainder 6

    -> 100 = 64h


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 2,813 ✭✭✭Gone Drinking


    Just curious why you'd need to work it out manually? Or is it just to understand it better?


  • Registered Users, Registered Users 2 Posts: 1,731 ✭✭✭GreenWolfe


    Just curious why you'd need to work it out manually? Or is it just to understand it better?

    It's around exam time for the colleges, homework of some kind I'd guess.


  • Registered Users, Registered Users 2 Posts: 1,931 ✭✭✭PrzemoF


    I'd suggest to learn how doc->bin and bin->dec works - it's easy.

    And the rest of the crowd (oct & hex) can be created from bin on-the-fly

    example (first memorize 128-64-32-16-8-4-2-1):

    i.e. 100 to hex
    pick 64 - it's the first smaller than 100

    100-64 = 36
    pick 32 - it's the first smaller than 36
    36-32 = 4

    so (dec) 97 = (bin) 01100001:
    128 64 32 16 8 4 2 1
    0 1 1 0 0 1 0 0

    (bin) 0110 0001 = (hex) 64 as (bin) 0110 -> 6 and (bin) 0100 -> 4

    BTW google is asking similliar questions during interviews (i.e. convert 27 to bin)


Advertisement