Try the following:
$price=number_format($price,2,'.',',');
Try the following:
$price=number_format($price,2,'.',',');
Please follow the rules as posted on daniweb otherwise in future you may have to suffer the consequences such as point deduction or banning. So please keep your code tidy by placing it in the appropriate code tags and it isn't nice when long sentences are purely in caps. So try not to break any more rules in future.
Our Web Development forum category encompasses everything related to building a website from the ground up. Topics include serverside scripting, clientside scripting, databases, and web / graphic design. When posting programming code, encase it in [ code], [ code=syntax], or [ icode] bbcode tags. Please only link to your website if it is necessary to demonstrate how something isn't working.
Our PHP forum is the place for Q&A-style discussions related to this popular development language. LAMP programmers will appreciate our separate Apache forum, within the Networking sub-category of the Hardware and Software category, and MySQL forum, also within the Web Development category.
As per the question you have asked it is in the following syntax that you need to correct:
$result = mysql_query($sql) or die(mysql_error());
Notice the "or die(mysql_error());" after the mysql_query() function. This will reviel the true error which is a sql syntax error for your mysql query input ($sql). By fixing the $sql variable or the string you manually inputed you will solve the entire problem. So do "or die(mysql_error());" after each mysql_query()" and tell us the new error.
SimpleXML is a object oriented PHP module for dealing with interpreting XML code. So if your not using XML code or not Pre-Processing XML code then you can probably ignore this module. Like always the manual is a good place to start and perhaps a few tutorials might even help.
Manual link: http://au2.php.net/manual/en/book.simplexml.php
You need the table name conjoined to the column name. For example:
SELECT * FROM admin INNER join category on category.cat_id=admin.cat_id where category.cat_id=5
Does anybody know if OpenGL has been written in Java instead of it's normal C language. If it hasn't then I might have some fun converting OpenGL from C to Java so that any Java application can run OpenGL.
Although I haven't got much code from your post I liked liked the first bullet point.
Basically to achieve my goal, I need an algorithm for creating a textured semi-sphere which is always at the same position where the inside center of the semi is pointing flat towards the camera where the camera is the display area of the applet. And then the sphere gets cropped in the middle as big as it can to get a square. Then this square that is cropped is the resulting image for the current view.
Also to pan left right up and down, the input image is patterned horizontally and vertically twice so the image reappears 4 times in the new source image although the vertical image will have the top part cropped in half and the bottom pattern cropped in half with an entire middle so it is like a grid of 2x3 where the 3 is contained of two half images (top and bottom) and a whole image in the middle. All of these images in the parent image are the same input image.
Then the image gets croped from specified positions and the width and height of the crop is equal to x=width/4 && y=height/2. So that new cropped image will then be processed in the sphere. But different positions to crop from (eg moving mouse changes crop position) will then result in different panning.
So my main question is how can I draw …
Hi,
I am rendering a bunch of cg images but now I need to make an applet that will view them. More specifically these images are very much like the first generation of google street view where you have a picture and you can get a camera to crop a section of the image and as you pan left, right, up or down the cropping moves left, right, up or down. However this presents one problem. I can only render as a spherical image and that is the equivelant of setting the texture of a sphere where the camera is inside the sphere. But as I know Java doesn't support 3d properly for applets. This means I need an algorithm to fake the allusion of the sphere object by re-arranging the pixels and removing some pixels. An example of the resulting image can be found at the below link.
http://farm5.static.flickr.com/4098/4922486529_9de8acb6a7_z.jpg
So my question is how can I turn an image such as the one above to a Java applet where you can pan around like street view without 3d Java?
Thankyou
cwarn23
But what if for example the ice caps melted and they all drowned while all of us on high ground died of starvation or became cannibals until there were only one gender left?
That is a very real possibility because when the ice caps melt then fish supplies will become scarce especially with the seas almost fished out leaving land animals and with populations more concentrated due to loss of land from the water level rising we would wipe out animal population leaving us fruit and veg. And that takes some doing to make which means there would have to be a massive die out of population to feed the human race. Then the survivors could die of a disease or UFO so there is another way that we could loose the battle of surviving on earth.
Does any species adapt better than us?
We have colonised almost every part of the planet, every enviroment from tundra to desert.
And yet we are so reliant on air conditioners, heaters, fans and organtic food which simply cannot exist in some situations. So in a way we are reliant on the very organisms that are vulnerable to extinction.
But what if I believe in a more apocalyptic event?
So you believe all of the tickboxes would happen plus more. Ultimately those are the only four elements that can destroy man/girl kind. Perhaps you could state how you think the earth will end and if your unsure on what to tick I'll tell you how it fits into which categories. :)
Need more poll choices :).
Well I made it simple. If for example it's floods/title wave/cyclone then you would select Water and/or wind. If however it is something like a meteoroid shower or collision with the earth or zero point module exploding then you would select fire. And so you can see how I made it into such larger categories.
Also could an admin make this poll end on the 21/12/12
thanks.
Below is a paragraph based on a true story of how floods rule the world 2011 to 2012.
[story]
The year is 2010 and everybody seems to be on top of the moon with great wealth when scientists monitoring the sun discover a potential solar burst from the sun which may or may not effect us.
January 2011 it is discovered that this solar burst will pass by the earths atmosphere but not collide with the earth itself. Calculations are done to prepare this data for the media and who is may concern.
Around February 2011 unusual weather patterns start to appear all around the world including record cyclones and record catastrophes. Then Floods and Cyclones devastate millions in Australia.
March 2011 an earthquake appears in Japan causing damage to infrastructure and shaking up the market.
2012 the biggest part of the solar burst arrives with record storms and flooding as well as blackouts and earthquakes appear all around the globe over a period of time.
Is this all a coincidence or is the mein calender more accurate than some thought.
[/story]
Perhaps 2012 is when climates change and species who don't adapt will not survive including humans. So my guess is while it's not the end of the world many species are due to extinct in 2012 and we might be on the chopping list depending on how bad this solar flare is. All of the information in the story …
cool. My new computer specs are starting to piece together. Although I would be happy with such a cpu I'll see if Intel can beat those specs in december this year first.
Also I know this isn't entirely related but say I had a graphics gpu (nvidia Quadro 6000) which has 1 terraflop. If I got two of those graphics cards would I then have 2 terraflops of gpu or would I still have just the 1 terraflop? Thank you for the great information :)
Another question. Can I somehow interface a server blade/rack to become a desktop computer so say I had a rack of 4 of the PowerEdge C6145 then could I use them like a desktop where each blade is like a separate desktop or is everything gotta be done by command line and by linux/unix. Because I would love it if I could buy 4x PowerEdge C6145 plus a rack and turn it on like a normal computer with a 4 normal monitors or maybe remote desktop with Windows 7 Professional 64 bit installed on each one. So please answer if I could install windows 7 on a server rack and use it like a normal computer with windows software etc. So please tell me if this is possible and if so then how so I can tell the techi when I buy it. Thanks greatly.
Nice server but I'm after a desktop machine with such a cpu and big graphics too (eg Quadro 6000). So can you please point me in the right direction.
Thanks.
Also I thought I would add the question -
Would it be better to get this hardware now or wait for the Sandy Bridge i7 Extreme because now I'm not sure on what to do as I don't have a clue what the Sandy Bridge i7 Extreme specs are meant to be like (eg how many ghz with how many threads+sockets)?
Hi, I was surfing the web looking at what technology is around then I found the below link and quotes the following:
how fast do you need it? because the magny-cours amd 12 cores come out early next year, and with an 8 socket motherboard you'd have 96 cores, whereas even with an intel nehalem 4P setup, you'd only have 24 cores and 48 threads.
Original Recourse: http://www.tomshardware.com/forum/263016-28-intel-xeon-x7460-cores-opteron-8380-cores
Then I saw 96 cores!!!. I want two of them. So before I can ask my local computer supplier to custom build two of them, I need to know what the model names of the amd cpu and the motherboard are and how much they cost. Also I would like to know how many GHz each core is. And the last question I have is, is it possible to have the nvidia Quadro 6000 graphics with this motherboard? So please post the details because I'm an interested customer.
Thanks
cwarn23
I just discovered after an IRC chat that the measurements are incorrect and as measured my script is slower. However I'll post an update for an algorithm that is 4-6 times slower than the php inbuilt algorithm and I am working on fixing the glitches I have made to make it faster. I'm sure I can make it 6 times faster somehow.
<?php
function mysq($in) {
$tmp = (int) $in;
$tmpp = ($tmp/2);
for ($x=0,$i=1;($i*$i)<=$tmp;$i*=2,$x++) {}
$i/=2;
for (;($i*$i)<=$tmp;$i++) {}
$i--;
$k=$i;
$i++;
if (($i*$i)>$tmp || ($i*$i)<$tmp) {
for ($j=1;($i*$i)>=$tmp;$j/=2,$i=($j+$k)) {}
$v=strlen((string)$j);
$m=1/pow(10,$v);
for ($g=(32-$x);$g>=0;$g--) { //32 is for 32 bits
$z=$m*pow(2,$g);
for (;($i*$i)<=$tmp;$j+=$z,$i=($j+$k)) {}
$j-=$z;
$i=$j+$k;
}
if (($i*$i)>$tmp || ($i*$i)<$tmp) {
//$w = (strlen((string)pow(2,32))+1);
//$w = same number as below
$w = 11; //32 bit
$q=$m;
for ($n=$v+1;$n<$w;$n++) {
$m=1/pow(10,$n);
$p=pow(10,(($n-$v)+1));
if ($m>5) {
for ($o=0;$o<$p && ($i*$i)<=$tmp;$j+=$m,$i=($j+$k),$o++) {}
$j-=$m;
$i=($j+$k);
} else {
for ($o=0;$o<$p && ($i*$i)>=$tmp;$j-=$m,$i=($j+$k),$o++) {}
$j+=$m;
$i=($j+$k);
}
}
}
}
return $i;
}
$s = microtime(true);
mysq(128);
$e = microtime(true);
$a=($e-$s);
unset($e,$s);
sleep(1);
$s = microtime(true);
sqrt(128);
$e = microtime(true);
echo 'mysq time ='.rtrim(number_format($a, 64, '.', ''),'0').'<br>';
echo 'mysq result='.mysq(128).'<br>';
echo 'sqrt time ='.rtrim(number_format(($e-$s), 64, '.', ''),'0').'<br>';
echo 'sqrt result='.sqrt(128).'<br>';
echo 'The mysq function is '.rtrim(number_format(($a/($e-$s)), 64, '.', ''),'0').' times faster for this calculation.<br>';
Hi, I have just created an algorithm and could this be the greatest algorithm invented for calculating square roots? Perhaps the answer is yes with 100% accuracy unlike some algorithms that round the last digit up. Below is the algorithm I have created and I used php. Also this algorithm can easily be imported into any language with any bitrate and is very scalable unlike some of the standard built in square root algorithms for some interpreters (all of the ones tested so far). Now below is the code with it in both the form of a class and the form of a function.
You may notice that the function name is funny but it is tatically named that way so that the string length of the function name is the same as the sqrt() function so you don't get qwerky results when comparing the two.
<?php
class sqrt {
public $value;
function __construct($in) {
$tmp = (int) $in;
$tmpp = ($tmp/2);
for ($i=1;($i*$i)<=$tmp;$i*=2) {}
$i/=2;
for (;($i*$i)<=$tmp;$i++) {}
$i--;
$k=$i;
$i++;
if (($i*$i)>$tmp || ($i*$i)<$tmp) {
for ($j=1;($i*$i)>=$tmp;$j/=2,$i=($j+$k)) {}
$v=strlen((string)$j);
$m=1/pow(10,$v);
for (;($i*$i)<=$tmp;$j+=$m,$i=($j+$k)) {}
$j-=($m);
$i=$j+$k;
if (($i*$i)>$tmp || ($i*$i)<$tmp) {
//$w = (strlen((string)pow(2,32))+1);
//$w = same number as below
$w = 11; //32 bit
$q=$m;
for ($n=$v+1;$n<$w;$n++) {
$m=1/pow(10,$n);
$p=pow(10,(($n-$v)+1));
for ($o=0;$o<$p && ($i*$i)<=$tmp;$j+=$m,$i=($j+$k),$o++) {}
$j-=$m;
$i=($j+$k);
}
}
}
echo $i;
$this->value = $i;
return $this->value;
}
}
function mysq($in) {
$tmp = (int) $in;
$tmpp = ($tmp/2);
for ($i=1;($i*$i)<=$tmp;$i*=2) {}
$i/=2;
for (;($i*$i)<=$tmp;$i++) {} …
I can find stuff about the vaccine but I can't find anything about this bacteria thing your talking about I'm a Bio geek as well so could you post a link with more info?
ok.
I got most of the information for a local telivision report and other bits from various parts of the web. However, I have managed to find an old news artical which bill gates based his research on.
http://www.upi.com/Science_News/2009/05/13/Study-Bacteria-might-stop-malaria-spread/UPI-32761242250619/
This news artical was published in 2009 and contains the same concepts that bill gates followed through to get the final result. If you want more information then just let me know because just like you I find there is very little information on the web about this since not all of it is official yet although is promising after some successful human trials have already occured. But as I said, most of the information in my first post was based on a telivision news headline and incase you wanna know the news station it is "10 News" in Australia.
External hard drives and flash drives are much slower than the internal hard drive(s). Unless you have USB 3.0 ports then I would go with the internal hard drive but, bear in mind, writing and re-writing things on your hard drive will wear it out. I can't wait until solid state hard drives become common because they are so much more reliable.
As a retro gamer I think the best games are between 32 and 125k in size. ;)
Agreed to some extent however why use the old fashion USB technology for this job. Why not something like Gigabit ethernet or firewire. Both of which have faster speeds and make cheap alternatives to an internal hard drive IF you have an irrelevant power supply. If however your power supply has enough wattage to handle another hard drive then by all means the internal drive is a better and more efficient option.
Or at lease one disease - Malaria.
Human trials have already proven successful by injecting some Mosquitos with a bacteria to disable the harmful chemicals the Mosquito would normally inject into a human then sends a bunch of these mutant Mosquitos into an active population of Mosquitoes where the offspring will carry the disability feature allowing us humans to eventually have no or few harmful Mosquitos in our human population as all Mosquitos would have this disibility feature when the older/current generations die out.
I could have explained it in a complicated scientific way but I don't think any computer geeks would understand the dna science behind it so that above is english only. Not that I would want to use Python or Monty Python to explain it.
Anyways back on subject. How do you feel that in about 10 years bill gates will be able to say he cured disease due to the research he started in 2002?
Hi, I am looking forward to getting the new i9 core when it comes out and I hear one of the cpu's that are going to be available is 4GHz 6 core 12 threaded. I'm going to wack two of those cpu's with dual sockets into my new computer. I use this cpu mainly for heavy duty rendering and for lots of brute force. So while we can't be certain about what is going to happen lets speculate. For example, we know the i9 is based on 6 core processors and the largest processor will be 4GHz so what will you do with this cpu and what date do you think it will be released as it is currently only known to be the first half of 2011 and what processors do you believe the i9 will contain?
They are both LGA1366 sockets, so they will be compatible.
As I said in my last post though, I suggested the 980X earlier and you said it was too tiny for your needs.
Well perhaps I did a few incorrect calculations on my part (sorry :() but seems it will barley do the trick. But "barley do the trick" is better than nothing. :)
So all is good and thanks for the help even after some troubles I stumbled across and just to let you know I have given rep points to each of you's for being able to put up with me for such a long time. Thanks.
I would agree with you there but if I was to purchase the i7-980X then would the Xeon motherboard suggested allow for dual i7 sockets?
I apologize, I did read the wrong thing.
Since you want to game, I suggest this motherboard http://www.newegg.com/Product/Product.aspx?Item=N82E16813188070
2 of this cpu http://www.newegg.com/Product/Product.aspx?Item=N82E16819115223
4 sets of this ram http://www.newegg.com/Product/Product.aspx?Item=N82E16820145224and either a single 480 gtx or two 460 gtx's
Then just get an appropriate psu and some hard drives. this will give you the best balance between gaming and rendering.
hope this helps
Could somebody (or original poster) just confirm that the suggested motherboard is compatible with the cpu because the page says it's for Xeon. Can somebody elaborate/explain on this for me? Other than that I think my problem is pretty much solved.
I'm wondering if you realize that this program is Graphics card rendering intensive, not cpu?
you may want to read this. http://sites.google.com/site/sketchupsage/faster/computer
This is a Single Core Optimized program ie. what I posted before, having 32 cores wont help you at all.
From what you are saying only applies to google sketchup itself. It does not apply to it's extension twilight render. Perhaps the below link will clear things up on this subject.
http://www.twilightrender.com/features
Also the twilight render is multithreaded and I know that for a fact as I have seen "twilight render" render on all 8 threads 100% cpu of a i7 3.2GHz 4 core 8 threads. However as you say the editing tool itself (Sketchup) won't take advantage of the additional cores nor does it need to. It is only twilight the plugin which will take advantage of the additional cores allowing for a maximum quality imagery render.
As for where I am with this problem, I need something with big cores as previously mention (eg 3GHz minimum and preferably 4GHz) which has 6 core or 12 thread at 4GHz or if it's 3GHz per core, then it would need to be 8 core 16 thread each option with an associated motherboard of 2 sockets. So basically three options on the board. In case you missed them they are:
3GHz 8 core 16 thread with associated mother board dual sockets
4GHz 6 core 12 thread with associated mother board dual …
The program that I am using is called "Twilight Render" and is a plugin for google sketchup. It has a demo version and there is also a premium version for $99 USD. I'm planning to get the premium version at the same time as this new computer. Also I am sure that this program will be able to handle up to 255 threads ((2^8)-1) or at the very least 15 threads ((2^4)-1). So for that reason I want each core to be a decent number of GHz in the event of a 15 thread limitation. However I will need 2 extra threads on top of the rendering so that I can do regular work while it's rendering. So I am looking at something like 4GHz 6 core x 2 sockets if possible. Also is it possible to get cpu and motherboards custom built because that seems to be the major problem with the limited high end range on the market. Also this computer needs to be able to handle some 3d games I have been building in the c++ irrlich engine. I figured logically a big computer with big graphics would handle these game no problem but maybe I was wrong.
So could somebody point me in the right direction even if the cpu will only exist in another 6 months, where could I get a 4GHz cpu 6 core with a dual sockets motherboard that will allow for both extreme gaming and extreme rendering/processing? Also I would prefer …
@crunchie
If motherboards support multiple sockets and multiple sockets don't make any difference on performance then why do they exist? Obviously the don't exist for the i7 range but for the AMD cores sockets from a quick glance appears to be a popular feature?
@saxmaster49
Thanks for those two links and the Xeon is what attracts my eyes. After reading closely is it true that it can have 4x any xeon core with a maximum of 32 core? Also can this be used as a desktop computer with something like 2GB graphics? Thanks for that is it is greatly appreciated. By the way the software I am using doesn't support cluster computing but the reason for the high cpu rankings is because I am using parts of the program that were never meant to be used until another 10 years from now when cpu's would be by far greater.
You are dreaming then, to be honest. I have a 6 core processor and I have it running at 4050Mhz. Each core runs at exactly the same speed. You cannot simply add them together and get 24300Mhz. It just doesn't work that way. I wish I could say it did :).
Doesn't matter how many cores you have, they still will only run at a given speed.
If you have software that is multi-threaded and can take advantage of multiple cores though, then that is where you will get a faster rendering result.
Well adding the cores is a statistical way of doing a comparison of what you get between different cpu's with different number of cores and different core sizes. So basically by adding the threads together, you can get a true comparison between different cpu's and to some degree, makes it easier to see what performance you would expect. A bit like using the term vegitables to compare apples and oranges. Although indeed you are correct that it isn't scientifically proven, however it is instead a statistical measurement unit for comparison. So if you like I can convert the statistical measurement into several formats for you to make it easier. For this example I'll use what I require which is 100GHz. Below is a two examples to get 100GHz in the technical format.
3.2GHz 16 core 32 threaded
2.1GHz 24 core 48 threaded
So the above two examples are also examples of the …
I think you can get PSU's up to 1500 watt now :).
To be honest, if you want the fastest PC around, go for the 980x cpu. http://www.google.com.au/search?hl=en&source=hp&q=980X&aq=f&aqi=g10&aql=&oq=&gs_rfai=
I just checked the cpu that you posted and it is a tiny cpu compared to my needs (6 core 12 threads 3.33GHz :( ) I need something more like 3.33GHz 16 core - 32 threaded at minimum. Preferably something that totals the threads to between 100GHz and 150GHz. But any more than that I would happily pay for as I calculated for a truly efficient job, I would require 850GHz (all threads added up). So as you can see I am stuck in the middle of a rock and a hard place where the technology simply doesn't exist. So what would be your recommendations on the how abouts of achieving lets say 125GHz for a desktop PC cpu (all threads added up that is).
In case you wonder what I would do with ever so much cpu, I am rendering computer generated animations that are high definition and can last for about 10mins each animation at a frame rate of 30 frames/images per second using ray tracing and progressive rendering technology.
Then will the new Intel i9 series when it's released have any multi socket functionality like the current Xeon or am I mistaken on that one?
Also I think I found a power supply on ebay which can do 900 watt but I'm hoping it's a computer power supply as I would look silly giving the techi the model number to something like an air conditioner power supply. ;)
Hi, I'm trying to get a new computer but even the computer techi is stuck on this one. The basic situation is I'm buying a custom built computer and I need to find an appropriate motherboard. The thing that makes this request different is that the motherboard needs to be able to have 3 to 4 i7 cores (i7 core socket inputs/outputs) attached to it so that I can get 3-4 times the speed of a regular i7 core. So the first question is does anybody know of any mother boards with 3 or 4 sockets in them that will accept i7 cores in each of those sockets.
The second question is a minor one regarding the power supply to power all of this stuff. So the second question is are there any powerboxes that can supply about 900 Watt or what is the practical limitation on the power supply?
Note the the core (i7) is intel based and none of the other components have been decided yet.
Thanks for your time.
cwarn23
Don't you just get sick of hash algorithms constantly been brute forced or even cracked. Well here is an algorithm I have created in my spare time to help out the little guy who just wants a secure hash. This hashing algorithm uses many different techniques including ones used in sha1 to prevent a reversal algorithm and uses a lot of math to help reduce the speed of brute forcing the algorithm.
An example of the brute force done on common algorithms today is like I myself have got a website to brute force sha1, sha256, sha512, md4 and md5. Currently I am using a i7 3.2GHz 4 core 8 threads but in just over a year I will have in addition to that, another machine with an Xeon 2.27GHz 16 core 32 threads where there are 2x 8 core cpu boards connected to the motherboard doubling the performance along with 18TB of harddrive space and 9 individual hard drives. And I'm not the only one doing this. I have seen people who own 6 servers each with an Xeon processor 2.27GHz 8 core each. The conclusion, don't use a staight foward pre-made algorithm that has been around for a while. Instead hash a substr() of a hash or make a custom algorithm like this so that nobody can use pre-existing databases to reverse a hash.
Cool. I'm gonna love my new cpu (Xeon 2.27GHz 8x2core (16 core/32 threads total)) for my latest computer. Thanks for the information as I really need this extra cpu.
This test said I had an IQ of 100.99. Well I guess this makes me average.
If you were a pie then what would your last ord(chr(X)) be?
Answer 0 as pi as in 3.14159265 ends in 0.
Hi, I was thinking of buying an 8 core Xeon 3.0GHz (16 threaded) cpu but still want more. Is it possible to buy two of these cpu's and stick them both in the same computer sharing the same power supply, graphics card etc. I know this might be a silly question but maybe there is something like a mini server rack with a couple of cpu boards that I could buy in the one unit. So the question is - is it possible to put multiple cpu boards in the one computer (boards not cores). The other question is if not then are there any items like server racks with 2-4 slots for these cpu inserts? Thanks.
Hi everybody. I have a question about the best way to retrieve a list of possible source values from the & operator without checking every combination between the range required. The basic problem I face is I have (a&b)=c I know the values of b and c but need to find all possible values of a. Also note the minimum value of a is equal to c and the maximum value of a is ~(b^c) as demonstrated below. So I have already got in two variables the minimum and maximum possible values of a. Now I need to find the possible values between that range (a 64 bit range or unsigned long int). Can anybody tell me a more cpu efficient way of doing the below get_array() function as it hogs too much cpu especially after I put that function in a long loop. Like is there any way I can just get the binary value of the number and mathematically generate possible numbers based on where 1's and 0's pair with the maximum possible number and the variable b used on the first couple of lines?
import os
import operator
a = 20 #answer to fetch
b = 11247
c = (a & b)
num = (b ^ c)
def xnot_inversebin(n):
count=32
#"""returns the binary of integer n, using count number of digits"""
n = "".join([str((n >> y) & 1) for y in range(count-1, -1, -1)])
bin = ''
for i in range(0,32):
if n[i] == '0':
bin+='1' …
After spending 2 days browsing google and reviewing code I managed to find the solution. As hard as it first seemed the answer is pretty simple. Python can easily do the (a & b) part but when it comes to the ~ operator on a 32 bit number, Python automatically reduces the bit rate to the minimum bit rate required resulting in undesired effects when using it. So I created a little function that simulates the c++ bitset functionality in the previous examples which maintains the 32 bits in the number and changes 1's to 0's and vice versa. I'm so glad and surprized that I could do it as I'm a noob in both C++ and Python. Amazing the power of google devided by time(). :) Have a nice day. *solved*
a = 20 #answer to fetch
b = 11247
c = (a & b)
num = (b ^ c)
def xnot_inversebin(n):
count=32
#"""returns the binary of integer n, using count number of digits"""
n = "".join([str((n >> y) & 1) for y in range(count-1, -1, -1)])
bin = ''
for i in range(0,32):
if n[i] == '0':
bin+='1'
else:
bin+='0'
return int(bin,2)
print xnot_inversebin(num)
print c
I just discovered the following code cannot be converted to python because it uses the bitset library. Can anybody modify this code so it uses native binary operators such as no external dependencies?
std::bitset<NBITS> b(11247UL), c(1000UL) ;
std::bitset<NBITS> tmp = ~ (b ^ c);
std::cout << tmp.to_ulong() << "\n";
You can actually bind C and C++ libraries to python, that way you wouldn't need to re-write the code, and would still get the efficiency of the original library.
Well I need to be able to make constant changes to the library without having to recompile the library. Nice idea but not for this situation.
Hi, I thought this topic was solved at the time but now I have bumped into a problem using vijayan121's formula. I was using the formula ~(b^c) to get variable A but doesn't seem to work for some odd reason. Can you please revise the below formula to see what is wrong with it and note that it's done in python so that's why it may look strange.
a = 47 #a+x is 47
b = 88
c = (a & b)
print ~(b^c) #returns -81
print c #returns 8
Thanks for your time.
I just got some open source code from an irc member at internode and the code they provided works great. http://seattle.cs.washington.edu/svn/seattle/trunk/seattlelib/sha.repy
That is the link they gave me but I would love to here more on how to do it for sha256 sha512 and md4. Love the power of open source.
Hi,
I have just started python as after a chat with a friend I have discovered it would be the most suitable language for my latest project. The problem I have come across is I need a sha1 function written in python. I don't want to use the built in hashlib but I need an open source algorithm that I can modify. Can anybody help me on this one as google shows me nothing in the way of code snippets. Also I tried recreating the algorithm from scratch but turned out terribly hard to convert c++ code to python.
Thanks.
Hi, I have just got my computer back from the shop and to my surprise a 1TB harddrive which is dedicated to the root partition is nearly full. I'm using Ubuntu 9.10 64 bit and according to the command "du -hc" there is only 157M total in there. But when in the file explorer interface it says only 69.3GB is available which in fact ~990GB should be available of a capacity of 73.3GB. The Disk Usage Analyser also says the same as the file explorer interface. Then I went into the GParted program and it says that 931.51GB is occupied. So from what I can make out from these contradicting reports, I have just under 1TB and physically 931GB is occupied by blank ones and zeros not registered by the system. And mean while the system can only register the remaining 157M occupied along with all of the free space. Does anybody know how I can get back my 931GB without reinstalling the operating system?
Thanks.
That's it. I give up. The machine has won the match point. C++ CLR is ever so hard so for this project I'll switch to the php-gtk language as it will make things ever so much more simple. After 12 intensive hours my head now hurts and perhaps switching languages will be the ideal solution. I'll reward rep points to those who help when I needed it and thanks for the great help.
Could somebody please explain to me what is wrong with the following code as I struggle to write to a file.
void file_put_contents(std::string data) {
std::ofstream myfile ("datalog.tmp");
if (myfile.is_open()){
myfile << data;
myfile.close();
}
}
std::string file_get_contents() {
std::string line, res;
std::ifstream myfile ("datalog.tmp");
if (myfile.is_open()) {
while (myfile.good()) {
getline (myfile,line);
res+=line;
}
myfile.close();
}
return res;
}
If somebody can work out the answer that would be great but for now my patch might have to be to write to a text file from the thread functions and to get CLR to read the text file and update the fields accordingly. So if anybody has a better way I would love to hear it too.