Jump to content

Changes in values for mathematical things (Hex, Octal, Decimal and Binary)


Recommended Posts

I am wondering I used to be really good at doing the more Computer Science stuff with regards to converting Decimal (what PHP uses for floats), to Hexadecimal and then Octal and all that stuff.

 

I seem to have lost the ability to do this but just wondered if anyone knows of any good guides on the web that teach this? Looked through many but it's just not clicking at all, any reply is much appreciated infact massively appreciated.

 

Thank you so much and I look forward to any replies,

Jeremy

From decimal to hexadecimal is pretty easy if you know binary conversions. First convert to binary, then for each 4 binary bits, convert that value to its hexadecimal character equivalent. Octal, I've not had to deal with, so maybe someone else can chime in on that.

 

Decimal 143

Binary 1000 1111

First 4 bits 1000 = decimal 8 or 0x8

Second 4 bits 1111 = decimal 13 or 0xF

 

Decimal 143 = 0x8F

- Decimal means base 10. The least-significant digit is 10^0 (=1), the second-least is 10^1 (=10), third-least is 10^2 (=100) and so on. Thus "123" means 1*100+2*10+3*1 = 123.

- Binary means base two, so you get 1, 2, 4, 8... Thus "1010" means 1*8+0*4+1*2+0 = 10.

- Octal is 8 so "123" means 1*64+2*16+3*1 = 99.

- Hexadecimal is 16 so "123" means 1*256+2*16+3*1 = 291.

 

Then there's the shortcuts. 2^3=8 so you can convert binary/octal easily, and 2^4=16 so binary/hex is easy: just group digits by that second multiplier and convert the groups into digits.

"10101" in binary splits to "10 101" in octal (taking groups of three); 10 binary = 2 decimal = 2 octal, and 101 binary = 5 decimal = 5 octal, thus 10101 binary = 25 octal. For hex it splits to "1 0101" (groups of four); 1 binary = 1 hex, 0101 binary = 5 hex, thus 10101 binary = 15 hex.

 

Other trick, best for dealing with decimal->other base:

Take 143 decimal to binary. The highest power of two (two=binary) below that is 128 so write down a 1. Subtract (remainder 15) and halve 128 (now 64). 64>15 so write a 0. Repeat: 64/2=32 but 32>15 so write a 0. 32/2=16 but 16>15 so write a 0. 16/2=8 and 8

(You can do the same for other bases.)

 

 

Sorry if that sounds rushed. It is.

No no I appreciate your replies.

 

On a larger context though is there any really good guides on the basis for the fetch execute cycle also?

 

I just am going through some old things I studied at University and haven't looked at for ages, just some I have found tended to be quite confusing, it's really entirely out of fascination to be brutally honest.

 

Thank you though really appreciate those above replies!

Jeremy.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.