Write a function and calculate the sum of the two integers. Do not use +,-, *,/in the function body ,-,*,/For example, 5 + 17 = 22 first, think about how to add decimal.1) add to all without carry: After adding, the single digit is 2 (do not consider carry), the ten digit is 1, and the final addition result is 12;2) if there is an incoming bit, the value of the incoming bit: 5 + 7 in a single bit has an inc
, (DI) = 0205 h, (CX) = 0ch, ZF = 0. See p84
3.3.5 processor control commands and Miscellaneous Operation commands1. Mark Processing Command• CLC carry position 0 command CF defaults 0• CMC carry position 0 command CF highlight/CF• STC carry position 1 command CF Highlight 1• Set the CLD Direction Flag to 0 command DF limit 0• STD Direction Flag sets 1 command DF
Have you ever wondered why Computers add, subtract, multiply, and divide? Or, more directly, what is the principle of the computer?
Waitingforfriday has a detailed tutorial on how to create a four-digit computer by yourself. We can see how binary, mathematical logic, and electronics are combined to form the foundation of modern computers.
1. What is binary?
First, let's start with the simplest one.
The computer uses binary data. Each digit has only two possibilities: "0" and "1". The calcula
unsigned division.Idiv integer division.The above two items are returned:Commercial Al delivery, remainder ah, (byte operation );Or commodity delivery ax, remainder delivery dx, (word operation ).ASCII code adjustment for aad division.CBW byte conversion into words (extend the byte symbols in Al to Ah)The CWD character is converted to a dual character. (extend the character symbol in ax to DX)Convert the cwde character to a dual character. (extend the word symbol in ax to eax)CDQ dual-word exte
[Sword refers to Offer learning] [interview question 47: addition without subtraction, multiplication, division], sword refers to offer Question: To write a function and calculate the sum of two integers, The +,-, ×, and limit operators must not be used in the function.Solutions
The binary value of 5 is 101, and the binary value of 17 is 10001. We still try to divide the calculation into three steps: the first step is to add but not to carry the resul
Question:
You are given two linked lists representing two non-negative numbers. the digits are stored in reverse order and each of their nodes contain a single digit. add the two numbers and return it as a linked list.
Input:(2-> 4-> 3) + (5-> 6-> 4)Output:7-> 0-> 8Solution:
Just add them one by one. Pay attention to carry and boundary processing.Code:
1 /** 2 * Definition for singly-linked list. 3 * struct ListNode { 4 * int val; 5 * Lis
Calculate the sum of of the integers a and b, but is not allowed to use the operator + and - .Example:Given a = 1 and b = 2, return 3.Credits:Special thanks to @fujiaozhu for adding this problem and creating all test cases.Subscribe to see which companies asked this questionThe subject is to investigate the internal realization of the principle of addition.One binary additionFirst we give a truth table for binary addition, and then we analyze the truth table to get the rules of binary addition.
2. Add the NumbersYou are given, linked lists representing, and non-negative numbers. The digits is stored in reverse order and all of their nodes contain a single digit. ADD the numbers and return it as a linked list.Input: (2, 4, 3) + (5, 6, 4)Output:7, 0, 8Problem Solving Ideas:1. Where one of the linked lists is empty;2. The length of the linked list is the same, and the last node is added with a carry case;3. The length of the list is not equal,
0x01 Jump InstructionIn general, there are two kinds of JUMP commands in x86:1. Arithmetic jumps, such as JZ (jump if zero), JC (Carry), JNC (jumping if not carry), etc.2. Compare Jumps: Like JE (jump if equal), JB (jumping if below), JAE (if above or equal), etc.The first type of jump applies after an arithmetic or logical instruction, for example:Sub eax, Ebxjnz Result_is_not_zero and ECX, EDXJZ. The_bit_
());} /*** Recursive calculation of factorial* @param L* @return*/public static int[] Getfacorial (int n){if (n = = 1) return new int[]{1};int[] Multiplytolen = Multiplytolen (getfacorial (n-1), n);return Multiplytolen;} /*** The main algorithm is the same as BigInteger, except that I only keep 9 bits per int for output.* @param value* @param n* @return*/private static int[] Multiplytolen (int[] value, int n){n may be greater than Max, divided into twoLong DH = N/max;Long dl = n% MAX; After 32
The API: int read4(char *buf) reads 4 characters at a time from a file.The return value is the actual number of characters read. For example, it returns 3 if there are only 3 characters left in the file.read4by using the API, implement the function that int read(char *buf, int n) reads n characters from the file.Note:The read function may be called multiple times.Analysis:Since The function can be called multiple times, we need to record the left over content in the buffer of read4, and put T He
A two-way encryption/decryption method (php) Base on hexadecimal conversion
// Made by huyang @ 2005-01-20 | 11-04-06# Use n-carry to m-carry#0 ~ 9A-Z, which can be understood as a 36-digit range at mostPrint'Encryption and decryption method';Class carry{Function carry ($ n, $ m){$ This-> n = $ n;$ This-> m = $ m;$ T
! It should be-13. We still need to reduce the number by 16, but we just mentioned that positive numbers do not need to be reduced. What's wrong? Think about it.It turns out that if we explain the binary data in the preceding way, the range of the Four Binary values can only be [-8 ~ 7], in fact, if the register overflows from the left side, its value is in [... 0 \ 1 \ 2 \ 3 \ 4 \ 5 \ 6 \ 7 \-8 \-7 \-6 \-5 \-4 \-3 \-2 \-1 \ 0...] this is a continuous loop. That is to say, the previous-13 is rou
the array, and the result should beRESULT[0] 4RESULT[1] 2RESULT[2] 1This certainly is no problem, an int type data holds a number less than 10 is absolutely not overflow. But it's a little tricky to deal with.The whole array is treated as a number, and when multiplied by a number, it is necessary to multiply each bit with the multiplier and add the previous carry. The arithmetic is the same as the primary mathematics, the product of the bits is the c
offset that holds the next instruction to be executed in the code snippet. With the prefetch command work
In the system, the next instruction to be executed is usually prefetch to the instruction queue unless a transfer occurs. So, in understanding their function
, the existence of a command queue is not considered.
In real mode, because the maximum range of each segment is 64K, therefore, the EIP in the high 16-bit is certainly 0, at this time, equivalent to only its low 16-bit
IP to reflect
Title: Write a function that asks for the sum of two integers, requiring no use of +,-, x, and/or in the body of the function. Analysis: This is another interesting topic to examine divergent thinking. The key to solving this problem is how to break through conventional thinking when something we are accustomed to is limited.
See this topic, my first reaction is dumbfounded, arithmetic can not use, that also what ah? But the problem is always to be solved, can only open thinking to think of var
/*Title:Author: ChengTime: September 11, 2002 (11:52:00-16:26:00)A large integer factorial processing function with recursive algorithmTime: September 16, 2002 (18:38:00-20:02:00)Recursive method to realize "Fibonacci sequence" problem*/ : ============================ recursive method for "large integer factorial" problem ===========================#define MAXN 1000//maximum number of data digitsThe order of integer k is obtained by recursive method, and the result is put into array arrays.void
. Consider the carry relationship, for example, 9 + 99999
4. In the final carry, an additional val = 1 node is required.
Implementation Method 1 (initial ):
Method 1 is the result of drawing the gourd according to the above idea.
But in fact, there are too many duplicates in the code in this question, and we always need to use the pre variable to track the front node, which is redundant.
/*** Definition fo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.