Hex values ???????
-
Hi , can anybody give me a little explanation on what things like : 0x0001,0x48,0xFF,...... mean? m0n0
This means you are in base 16 : it goes like this 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,12,... so A actually means 10 0x10 means: 1 * 16 + 0 = 16 0xFF means: 15*16 + 15 = 255 ... The reason hexadecimal is used is because 16 is a power of 2, so it is extremely easy to transform hexadecimal numbers into binary (and computers kinda like binary) 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 6 = 0110 7 = 0111 8 = 1000 9 = 1001 A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1111 Therefore let say the following number 0x9AD has got the following binary value 1001 1010 1100 I hope this helps, Jerome
-
This means you are in base 16 : it goes like this 1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,10,11,12,... so A actually means 10 0x10 means: 1 * 16 + 0 = 16 0xFF means: 15*16 + 15 = 255 ... The reason hexadecimal is used is because 16 is a power of 2, so it is extremely easy to transform hexadecimal numbers into binary (and computers kinda like binary) 0 = 0000 1 = 0001 2 = 0010 3 = 0011 4 = 0100 5 = 0101 6 = 0110 7 = 0111 8 = 1000 9 = 1001 A = 1010 B = 1011 C = 1100 D = 1101 E = 1110 F = 1111 Therefore let say the following number 0x9AD has got the following binary value 1001 1010 1100 I hope this helps, Jerome
Thanks Jerome for your attention. You know i have written several functions for Adding,Subtracting,Multiplying,.... huge numbers, my functions look like : CString ADD(CString s1,CString s2) CString SUB(CString s1,CString s2) ... CString TO_BINARY(CString s1) you see i have a function as shown above TO_BINARY , which means that it does smth like this (just example) CString g = ToBinary("13");//so g="1101" and this function is too slow when instead of "31" i enter number with 100 digits or more, Could you please give me any idea if i can use theses 0x000,... or smth similar to make my algorithm faster Regards m0n0
-
Thanks Jerome for your attention. You know i have written several functions for Adding,Subtracting,Multiplying,.... huge numbers, my functions look like : CString ADD(CString s1,CString s2) CString SUB(CString s1,CString s2) ... CString TO_BINARY(CString s1) you see i have a function as shown above TO_BINARY , which means that it does smth like this (just example) CString g = ToBinary("13");//so g="1101" and this function is too slow when instead of "31" i enter number with 100 digits or more, Could you please give me any idea if i can use theses 0x000,... or smth similar to make my algorithm faster Regards m0n0
The simplest algorithm I can think of - and it does not mean it is the most efficient - is the following Is the number odd, insert a "1" at the beginning of the string, a "0" otherwise Divide the number by two (integer divide) (or you can substract 1 or 0 before you do the divide so you do not have to bother with floats) If the result is 0, exit else start again The division by two is usually very efficient on binary numbers (operator >> ) but if your numbers are stored as strings it is irrelevant. Let me know! Good luck!