j.smith1981 Posted September 9, 2011 Share Posted September 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246791-changes-in-values-for-mathematical-things-hex-octal-decimal-and-binary/ Share on other sites More sharing options...
Pikachu2000 Posted September 9, 2011 Share Posted September 9, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/246791-changes-in-values-for-mathematical-things-hex-octal-decimal-and-binary/#findComment-1267519 Share on other sites More sharing options...
requinix Posted September 10, 2011 Share Posted September 10, 2011 - 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. Quote Link to comment https://forums.phpfreaks.com/topic/246791-changes-in-values-for-mathematical-things-hex-octal-decimal-and-binary/#findComment-1267537 Share on other sites More sharing options...
j.smith1981 Posted September 14, 2011 Author Share Posted September 14, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/246791-changes-in-values-for-mathematical-things-hex-octal-decimal-and-binary/#findComment-1269100 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.