Multiply Function [x]
08-03-2018, 05:33 PM
Post: #8
 Thomas Klemm Senior Member Posts: 1,447 Joined: Dec 2013
RE: Multiply Function [x]
(08-03-2018 01:07 PM)wynen Wrote:  The multiplication of the significants could be done by a shift and add algorithm. Wikipedia

Peasant or binary multiplication

Here's a program for the HP-11C:
Code:
LBL A       ; times STO 0       ; b a CLx         ; s=0 a LBL 0       ; while x<>y        ; a s x=0         ; a=0? GTO 2       ; done RCL 0       ; b a s STO+ 0      ; b → 2b x<>y        ; a b s 2           ; 2 a b s ÷           ; a÷2 b s s ENTER       ; a÷2 a÷2 b s INT         ; a'=⌊a÷2⌋ a÷2 b s x=y         ; 2∣a GTO 1       ; even R↓          ; a÷2 b s a' R↓          ; b s a' a÷2 +           ; s'=s+b a' GTO 0       ; while LBL 1       ; even R↑          ; s'=s a' GTO 0       ; while LBL 2       ; done R↓          ; s RTN         ;

This is a translation of the following Python program:
Code:
def times(a, b):     s = 0     while a != 0:         if a % 2 != 0:             s += b         a /= 2         b += b     return s

It works for positive integers $$a$$ and $$b$$ and calculates $$a\times b$$.

Cheers
Thomas
 « Next Oldest | Next Newest »

 Messages In This Thread Multiply Function [x] - Gamo - 08-03-2018, 09:27 AM RE: Multiply Function [x] - Massimo Gnerucci - 08-03-2018, 11:31 AM RE: Multiply Function [x] - Pekis - 08-03-2018, 01:04 PM RE: Multiply Function [x] - rprosperi - 08-03-2018, 01:13 PM RE: Multiply Function [x] - wynen - 08-03-2018, 01:07 PM RE: Multiply Function [x] - Dave Britten - 08-03-2018, 02:10 PM RE: Multiply Function [x] - Dieter - 08-03-2018, 02:40 PM RE: Multiply Function [x] - Thomas Klemm - 08-03-2018 05:33 PM RE: Multiply Function [x] - Thomas Klemm - 08-03-2018, 06:45 PM RE: Multiply Function [x] - Leviset - 08-03-2018, 10:54 PM RE: Multiply Function [x] - ijabbott - 08-03-2018, 11:05 PM RE: Multiply Function [x] - Gamo - 08-04-2018, 01:41 AM RE: Multiply Function [x] - Gamo - 08-04-2018, 04:23 AM RE: Multiply Function [x] - Namir - 08-04-2018, 08:26 AM RE: Multiply Function [x] - Thomas Puettmann - 08-04-2018, 09:03 AM RE: Multiply Function [x] - brickviking - 08-05-2018, 03:12 AM RE: Multiply Function [x] - Gamo - 08-05-2018, 03:33 AM RE: Multiply Function [x] - Thomas Klemm - 08-05-2018, 04:07 PM

User(s) browsing this thread: 1 Guest(s)
{"ft_lang_label":"__label__en","ft_lang_prob":0.6745002,"math_prob":0.9411408,"size":540,"snap":"2020-10-2020-16","text_gpt3_token_len":159,"char_repetition_ratio":0.09701493,"word_repetition_ratio":0.0,"special_character_ratio":0.32222223,"punctuation_ratio":0.14545454,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9745741,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-24T05:45:24Z\",\"WARC-Record-ID\":\"<urn:uuid:ee949c98-1500-40a4-bede-cbf3e90050e4>\",\"Content-Length\":\"24746\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:76acf17a-25a4-4939-b990-15905a0754f6>\",\"WARC-Concurrent-To\":\"<urn:uuid:5c0febd1-77f2-4982-a00e-14953ca2a662>\",\"WARC-IP-Address\":\"209.197.117.170\",\"WARC-Target-URI\":\"https://www.hpmuseum.org/forum/showthread.php?tid=11165&pid=101536&mode=threaded\",\"WARC-Payload-Digest\":\"sha1:LPSLQECUFBYEQBRHSEI2KLVJNFGKJVQJ\",\"WARC-Block-Digest\":\"sha1:AZVNMQDUEO2BIKZYPED6LRQN6CVMACPJ\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875145897.19_warc_CC-MAIN-20200224040929-20200224070929-00273.warc.gz\"}"}