Posts

binary - Adding and subtracting two's complement -

using six-bit one's , two's complement representation trying solve following problem: 12 - 7 now, take 12 in binary , 7 in binary first. 12 = 001100 - 6 bit 7 = 000111 - 6 bit then, flip bit two's complement , add one? 12 = 110011 ones complement + 1 ------- 001101 7 = 111000 ones complement + 1 --------- 111001 then, add 2 complement together 001101 +111001 ------- 1000110 = overflow? discard last digit? if 5 now, if have number like -15 + 2 i add sign magnitude on msb if it's zero? like: -15 = 001111 6 bit would add 1 @ end here before flip bits? = 101111 using two's complement represent negative values has benefit subtraction , addition same. in case, can think of 12 - 7 12 + (-7) . hence need find two's complement representation of -7 , add +12: 12 001100 -7 111001 -- this, invert bits of 7 (000111) , add 1 ---------- 5 1000101 then discard carry (indicates overfl...

Python HTTP Redirect requests forbidden -

i'm trying scrape website url redirected, programmatically trying gives me 403 error code (forbidden). can place url in browser , browser follow url though... to show simple example i'm trying go : http://en.wikipedia.org/w/index.php?title=mike_tyson i've tried urllib2 , mechanize both not work. new web programming , wondering whether there other tricks need in order follow redirect! thanks! edit okay, messed. looking alternative methods because trying scrape mp3. managing succesfully downloading mp3 mangled. turns out somehow related me downloading on windows or current python version. tested code on ubuntu distro , mp3 file downloaded fine.... so used simple urllib2.openurl , worked perfect! i wonder why downloading on windows mangled mp3? try changing mechanize flag not respect robots.txt. also, consider changing user-agent http header: >>> import mechanize >>> br = mechanize.browser() >>> br.set_handle_robots(f...

.net - Nhibernate Update does not persist change to database -

i have problem getting change(s) data object retrieved using nhibernate persist database. no exceptions it's difficult know look. suggestions? string name = "somenewname"; string repositoryid = "somerepositoryid"; isession nhbsession = getnhbsession(session); nhbsession.transaction.begin(); try { repositorydto existingrepository = nhbsession.get<repositorydto>(repositoryid); if (existingrepository == null || existingrepository.timedeleted != null) throw new exception("repository not exist in system or deleted. cannot modify."); existingrepository.name = name; //works fine here expected; in db old name nhbsession.update(existingrepository); nhbsession.transaction.commit(); } catch (exception ex) { nhbsession.transaction.rollback(); throw new exception("error modifying repository: " + ex.message, ex); } <?xml version="1.0" encoding="utf-8" ?> <hibernate-mapping xml...

ImageScience for Windows on Ruby 1.9 -

has have success installing imagescience on ruby 1.9 windows? unfortunately, using ruby 1.8 windows development. want upgrade ruby 1.9 performance improvement. able install of gems, haven't had luck imagescience. rob anderton had put in useful instruction installation on 1.8, used. seems started using mac since :) (i considering that, in meanwhile...) http://thewebfellas.com/blog/2008/2/18/imagescience-on-windows-without-the-pain try devil instead, works in windows: http://banisterfiend.wordpress.com/2009/10/14/the-devil-image-library-for-ruby/

c# - Check to make sure a number has been picked in each box -

Image
i want have check make sure user picked number in 2x2. if user doesnt pick number in 1 of boxes want messagebog popup telling user fill in boxes. look validation events , controls should start http://msdn.microsoft.com/en-us/library/f6xht7x2.aspx

c++ - Templated function being reported as "undefined reference" during compilation -

these files: --------[ c.hpp ]-------- #ifndef _c #define _c #include<iostream> class c { public: template<class cartype> void call(cartype& c); }; #endif --------[ c.cpp ]-------- #include "c.hpp" template<class cartype> void c::call(cartype& c) { //make use of c somewhere here std::cout<<"car"<<std::endl; } --------[ v.cpp ]-------- class merc {}; --------[ main.cpp ]-------- #include "c.hpp" #include "v.cpp" //#include "c.cpp" int main() { merc m; c somecar; somecar.call(m); }//main i'm able generate ".o" files above files, command g++ -c main.cpp , g++ -c c.cpp , on. when try linking ".o" files g++ -o car c.o main.o v.o error: main.o: in function `main': main.cpp:(.text+0x17): undefined reference `void c::call<merc>(merc&)' collect2: ld returned 1 exit status the error goes away when uncomment line ...

transparency - Delphi 6 : How to create a Bitmap with TextOut that has an Alpha channel? -

i'll describe overall goal in case question asked isn't in best form answer i'm looking for. have sphere of words or "word ball" spins around x axis. words spin (z coordinate goes -1 1, front back), intend change size , opacity of each word words in "front" 100% opaque , full-sized , words in smaller , transparent. prefer straight delphi code , avoid things direct3d, etc. have rotation code working fine. need implement z coordinate based perceptual shading idea. when create word ball dynamically create timage component each word. "print" word timage bitmap using tcanvas.textout() method in centered manner. intend use bitblt copy bitmap correct location in main canvas holds word ball, because bitblt fast , can resize bitmaps on-the-fly, meeting 1 of requirements perceptual shading operation. but don't know best way facilitate alpha blending. know windows has alphablend() call , seems straightforward use. need know how create...