Answer:
i) Total time = 2457.73 secs
ii) BDP = 0.01 Mbyte
Explanation:
Packet size : 2 Kb = ( 2 * 8192 ) bits = 16384 bits
Bandwidth : 2Mbps = 2,000,000 bits/sec
RTT = 50 ms = 0.050 secs
i) Determine total time required to transfer 500 kB
= Initial handshake + Time for transmission of all files + propagation delay
= 2 x RTT + Time for transmission + RTT /2
Total time = ( 2 * 0.05 ) + (1500 * 1.6384 )+ ( 0.050 / 2 ) = 2457.73 secs
ii) Determine the Bandwidth-delay product
= data link capacity * RTT
= 2 Mbps * 50 ms = 100,000 = 0.01 MByte
Write a void function SelectionSortDescendTrace() that takes an integer array and sorts the array into descending order. The function should use nested loops and output the array after each iteration of the outer loop, thus outputting the array N-1 times (where N is the size). Complete main() to read in a list of up to 10 positive integers (ending in -1) and then call the SelectionSortDescendTrace() function. If the input is:
Answer:
Explanation:
The following program is written in Java. The main method asks the user to enter 10 different integer values. These values are saved to an integer array and passed to the SelectionSortDescendTrace() method. This method sorts the array in descending order while printing the entire array after every outer loop cycle. The program was tested and the output can be seen in the attached image below.
import java.util.*;
class Brainly {
// Main Method
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int[] myArr = new int[10];
for (int i = 0; i < 10; i++) {
System.out.print("Enter an integer: ");
myArr[i] = in.nextInt();
System.out.print('\n');
}
SelectionSortDescendTrace(myArr);
}
public static void SelectionSortDescendTrace(int[] myArr) {
int temp;
for (int i = 0; i < myArr.length; i++)
{
for (int j = 0; j <myArr.length; j++)
{
if (j != myArr.length - 1)
{
if (myArr[j] < myArr[j + 1])
{
temp = myArr[j];
myArr[j] = myArr[j + 1];
myArr[j + 1] = temp;
}
}
}
System.out.println(Arrays.toString(myArr));
}
}
}
Cryptarithmetic algorithm
Answer:
CryptArithmetic or verbal arithmetic is a class of mathematical puzzles in which the digits are replaced by letters of the alphabet or other symbols. Usually it is required that each letter would be replaced by a unique digit. Each letter having different value from the other letters.
Explanation:
Cryptarithm now denotes mathematical problems usually calling for addition, subtraction, multiplication, or division and replacement of the digits by letters of the alphabet or some other symbols. ... Since D × B has only one digit, B must be 3 or less. The only two possibilities are 0 and 2.
Differentiate between TCP Reno and TCP Tahoe.
Answer:
They have different words
Explanation:
I hope it helps choose me the brainest
various gabs in the digital divide
Answer:
factors such as low literacy and income level Geographical restriction lack of motivation motivation of the technology lack of motivation to use technology and digital illiteracy and contribute to the digital device
Compute the acceleration of gravity for a given distance from the earth's center, distCenter, assigning the result to accelGravity. The expression for the acceleration of gravity is: (G * M) / (d2), where G is the gravitational constant 6.673 x 10-11, M is the mass of the earth 5.98 x 1024 (in kg) and d is the distance in meters from the earth's center (stored in variable distCenter).
#include
using namespace std;
int main() {
double G = 6.673e-11;
double M = 5.98e24;
double accelGravity;
double distCenter;
cin >> distCenter;
/* Your solution goes here */
cout << accelGravity << endl;
return 0;
}
Answer:
Replace /* Your solution goes here */ with the following expression
accelGravity = (G * M) / (distCenter *distCenter );
Explanation:
Required
Complete the code
The equivalent expression of (G * M) / (d^2) is:
(G * M) / (distCenter *distCenter );
The expression must be stored in accelGravity.
So, we have:
accelGravity = (G * M) / (distCenter *distCenter );
Develop a program that will maintain an ordered linked list of positive whole numbers. Your program will provide for the following options: a. Add a number b. Delete a number c. Search for a number d. Display the whole list of numbers At all times, the program will keep the list ordered (the smallest number first and the largest number last).
Answer:
#include <iostream>
using namespace std;
struct entry
{
int number;
entry* next;
};
void orderedInsert(entry** head_ref,entry* new_node);
void init_node(entry *head,int n)
{
head->number = n;
head->next =NULL;
}
void insert(struct entry **head, int n)
{
entry *nNode = new entry;
nNode->number = n;
nNode->next = *head;
*head = nNode;
}
entry *searchNode(entry *head, int n)
{
entry *curr = head;
while(curr)
{
if(curr->number == n)
return curr;
curr = curr->next;
}
}
bool delNode(entry **head, entry *ptrDel)
{
entry *curr = *head;
if(ptrDel == *head)
{
*head = curr->next;
delete ptrDel;
return true;
}
while(curr)
{
if(curr->next == ptrDel)
{
curr->next = ptrDel->next;
delete ptrDel;
return true;
}
curr = curr->next;
}
return false;
}
void display(struct entry *head)
{
entry *list = head;
while(list!=NULL)
{
cout << list->number << " ";
list = list->next;
}
cout << endl;
cout << endl;
}
//Define the function to sort the list.
void insertionSort(struct entry **h_ref)
{
// Initialize the list
struct entry *ordered = NULL;
// Insert node to sorted list.
struct entry *current = *h_ref;
while (current != NULL)
{
struct entry *next = current->next;
// insert current in the ordered list
orderedInsert(&ordered, current);
// Update current
current = next;
}
// Update the list.
*h_ref = ordered;
}
//Define the function to insert and traverse the ordered list
void orderedInsert(struct entry** h_ref, struct entry* n_node)
{
struct entry* current;
/* Check for the head end */
if (*h_ref == NULL || (*h_ref)->number >= n_node->number)
{
n_node->next = *h_ref;
*h_ref = n_node;
}
else
{
//search the node before insertion
current = *h_ref;
while (current->next!=NULL &&
current->next->number < n_node->number)
{
current = current->next;
}
//Adjust the next node.
n_node->next = current->next;
current->next = n_node;
}
}
int main()
{
//Define the structure and variables.
char ch;int i=0;
entry *newHead;
entry *head = new entry;
entry *ptr;
entry *ptrDelete;
//Use do while loop to countinue in program.
do
{
//Define the variables
int n;
int s;
int item;
char choice;
//Accept the user choice
cout<<"Enter your choice:"<<endl;
cout<<"a. Add a number"<<endl
<<"b. Delete a number"<<endl
<<"c. Search for a number"<<endl
<<"d. Display the whole list of numbers"<<endl;
cin>>choice;
//Check the choice.
switch(choice)
{
//Insert an item in the list.
case 'a' :
// cin>>item;
cout<<"Enter the element:"<<endl;
cin>>item;
//To insert the first element
if(i==0)
init_node(head,item);
//To insert remaining element.
else
{
ptr = searchNode(head,item);
//Check for Duplicate data item.
if(ptr==NULL)
{
insert(&head,item);
}
else
{
cout<<"Duplicate data items not allowed";
cout<<endl<<"EnterAgain"<<endl;
cin>>item;
insert(&head,item);
}
}
insertionSort(&head);
i=i+1;
break;
//Delete the item from the list
case 'b' :
int numDel;
cout<<"Enter the number to be deleted :"<<endl;
cin>>numDel;
//Locate the node.
ptrDelete = searchNode(head,numDel);
if(ptrDelete==NULL)
cout<<"Element not found";
else
{
if(delNode(&head,ptrDelete))
cout << "Node "<< numDel << " deleted!\n";
}
break;
//Serach the item in the list.
case 'c' :
cout<<"Enter the element to be searched :";
cout<<endl;
cin>>s;
ptr = searchNode(head,s);
if(ptr==NULL)
cout<<"Element not found";
else
cout<<"Element found";
break;
//Display the list.
case 'd' :
display(head);
break;
default :
cout << "Invalid choice" << endl;
break;
}
//Ask user to run the program again
cout<<endl<<"Enter y to countinue: ";
cin>>ch;
}while(ch=='y'||ch=='Y');
return 0;
}
output:
I have a variable and set it equal to 5. 1 then send it as an argument to a function that adds 5 to the variable passed in. Outside the function print the variable (after the function executes).
What will it print?
A. 5+1
B. 4
C. 6
D. 5
Answer:
D. 5
Explanation:
If the variables original value was 5 then the value that will be printed is 5. This is because the variable is being passed as a parameter into the function and 5 is being added to the parameter value, not the actual global variable outside. Therefore, in order for the adjusted value to be printed then that new value that is returned by the function needs to be saved in a new variable. This can be seen in the example code below.
Chassis intrusion detection is an option that can be enabled/disabled in the BIOS setup utility (if a BIOS comes equipped with this feature).Coupled with a hardware sensor mounted insided the computer case, this functionality can be used to check if the case was opened and display a notification alert during next boot.
a. True
b. False
Answer: True
Explanation:
Chassis intrusion detection is simply a vital security feature which is used typically by large corporate networks. It's simply an intrusion detection method which can be used in alerting a system administrator when there's a situation whereby a person opens a computer case which can then be investigated in order to know if the computer hardware has been tampered with.
It should also be noted that the chassis intrusion detection can then be either enabled or disabled in the BIOS setup utility if a BIOS comes equipped with this feature.
The correct option is True.
A light rag is striking the surface of earth. Which factor would make the light ray more likely to be absorbed than reflected?
Answer:
The answer is D.
Explanation:
because the other answers doesn't make sense.
You are working from home using a microcomputer, a DSL modem, and a telephone connection to the Internet. Your company is connected to the Internet and has both local area networks and a mainframe computer. List all the different network connections involved in this operation.
Solution :
It is given that I am using a microcomputer at home along with DSL modem as well as a telephone network for the internet. My company has internet and has local area network and also a mainframe network.
Therefore, the different network connections involved are :
local area network to the wide area networkmicrocomputer to the internet connectionYou are the network administrator for the ABC Company. Your network consists of two DNS servers named DNS1 and DNS2. The users who are configured to use DNS2 complain because they are unable to connect to internet websites. The following shows the configuration of both servers:
Server Configurations:
DNS1: _msdcs.abc.comabc.com
DNS2: .(root)_msdcs.abc.comabc.com
The users connected to DNS2 need to be able to access the internet. What should be done?
Answer:
ABC Company
The action to take is to:
Delete the .(root) zone from the DNS2. Then configure conditional forwarding on the DNS2 server. If this is not done, the users will be unable to access the internet.
Explanation:
DNS forwarding enables DNS queries to be forwarded to a designated server, say DNS2, for resolution according to the DNS domain name. This stops the initial server, DNS1, that was contacted by the client from handling the query, thereby improving the network's performance and resilience and enabling the users to be connected to the DNS2 in order to access the internet.
Suppose we can buy a chocolate bar from the vending machine for $1 each. Inside every chocolate bar is a coupon. We can redeem six coupons for one chocolate bar from the machine. This means that once you have started buying chocolate bars from the machine, you always have some coupons. We would like to know how many chocolate bars can be eaten if we start with N dollars and always redeem coupons if we have enough for an additional chocolate bar.For example, with 6 dollars we could consume 7 chocolate bars after purchasing 6 bars giving us 6 coupons and then redeeming the 6 coupons for one bar. This would leave us with one extra coupon. For 11 dollars, we could consume 13 chocolate bars and still have one coupon left. For 2 dollars, we could have consumed 14 chocolate bars and have two coupons left.Write a program that inputs a value for N and outputs how many chocolate bars we can eat and how many coupons we would have left over. Use a loop that continues to redeem coupons as long as there are enough to get at least one chocolate bar.
Answer and Explanation:
Using JavaScript:
/* program should take N input which represents the dollar amount and output how many chocolate bars and how many coupons we have*/
function chocolatebar(dollars){
var dollaramt= dollars;
var i;
for(i=0; i <= dollaramt; i++){
i=i+6
?
Alert ("you have 1 extra chocolate bar");
:
Alert ("keep buying chocolate bars to get more coupons for a bonus chocolate bar")
}
}
*
Based on the naming recommendations in the book, which of the following is a good identifier for a variable that will be used to hold an employee’s phone number? a. EmployeePhoneNumber b. emphonumber c. employee_phone_number d. empPhoneNum
Answer:
A good identifier for a variable that will be used to hold an employee’s phone number is:
a. EmployeePhoneNumber
Explanation:
An identifier is a string that uniquely identifies or names the entity or an object. The object or entity may be a constant, variable, structure, function, etc. Identifiers can be formed from uppercase and lowercase letters, digits, and underscores. Meaningful identifiers mostly favor the use of long descriptive names like EmployeePhoneNumber. However, the other options can still be used.
a) Importance of Software Engineering I
Answer:
os, operating system is very important
Assume a TCP sender is continuously sending 1,090-byte segments. If a TCP receiver advertises a window size of 5,718 bytes, and with a link transmission rate 26 Mbps an end-to-end propagation delay of 22.1 ms, what is the utilization
Answer:
for the 5 segments, the utilization is 3.8%
Explanation:
Given the data in the question;
segment size = 1090 bytes
Receiver window size = 5,718 bytes
Link transmission rate or Bandwidth = 26 Mbps = 26 × 10⁶ bps
propagation delay = 22.1 ms
so,
Round trip time = 2 × propagation delay = 2 × 22.1 ms = 44.2 ms
we determine the total segments;
Total segments = Receiver window size / sender segment or segment size
we substitute
Total segments = 5718 bytes / 1090 bytes
Total segments = 5.24587 ≈ 5
Next is the throughput
Throughput = Segment / Round trip
Throughput = 1090 bytes / 44.2 ms
1byte = 8 bits and 1ms = 10⁻³ s
Throughput = ( 1090 × 8 )bits / ( 44.2 × 10⁻³ )s
Throughput = 8720 bits / ( 44.2 × 10⁻³ s )
Throughput = 197.285 × 10³ bps
Now Utilization will be;
Utilization = Throughput / Bandwidth
we substitute
Utilization = ( 197.285 × 10³ bps ) / ( 26 × 10⁶ bps )
Utilization = 0.0076
Utilization is percentage will be ( 0.0076 × 100)% = 0.76%
∴ Over all utilization for the 5 segments will be;
⇒ 5 × 0.76% = 3.8%
Therefore, for the 5 segments, the utilization is 3.8%
A new PKI is being built at a company, but the network administrator has concerns about spikes of traffic occurring twice a day due to clients checking the status of the certificates. Which of the following should be implemented to reduce the spikes in traffic?
A. CRL
B. OCSP
C. SAN
D. OID
Answer:
Option A (CRL) is the right answer.
Explanation:
Certificates with respective expiration date canceled mostly by CA generating or providing them, then it would no longer be tolerated, is considered as CRL.CRL verification could be more profitable for a platform that routinely manages several clients, all having pronouncements from a certain CA, because its CRL could be retrieved once per day.Other given choices are not connected to the given scenario. So Option A is the right one.
A life insurance salesperson who takes advantage of the foot-in-the-door phenomenon would be most likely to:________
a. emphasize that his company is one of the largest in the insurance industry.
b. promise a free gift to those who agree to purchase an insurance policy.
c. address customers by their first names.
d. ask customers to respond to a brief survey of their attitudes regarding life insurance.
Answer:
d. ask customers to respond to a brief survey of their attitudes regarding life insurance.
Explanation:
A life insurance policy can be defined as a contract between a policyholder and an insurer, in which the insurer agrees to pay an amount of money to a specific beneficiary either upon the death of the insured person (decedent) or after a set period of time.
A salesperson (sales representative) refers to an individual or employee who is saddled with the responsibility of taking orders from customers, as well as selling finished goods and services to consumers or end users.
A foot-in-the-door phenomenon can be defined as a compliance (persuasive) technique or tactics that assumes a person agreeing to perform a small request increases the likelihood of he or she agreeing to a subsequent larger request. Thus, it posits that when a person agrees to a small, it makes it difficult for him or her to decline a second, larger (bigger) request.
In this context, a life insurance salesperson who takes advantage of the foot-in-the-door phenomenon would most likely ask his or her customers to respond to a brief survey of their attitudes regarding life insurance.
a computer cannot store the data and information for your future use true or false
why do we need vector graphics for creating logo
Answer:
hope it will help uplease mark brillient
Answer:
So we can maintain high quality designs at any graphic scale.
Explanation:
Unlike other graphic formats which simply define colors for fixed pixels, vector graphics define points and shapes (vectors) which are then used to draw the graphic at the desired and appropriate resolution.
Our graphic can look good at any resolution, no matter how large it gets. If we take a png or jpg file and make it extremely large, you'll notice the image begins to get blurry, because the pixels are being stretched and colors are being predicted or matched for the larger scale.
Give three reasons to use a hard drive as mass storage.
Answer:
With that in mind, let's take a look at five places where hard drives shine.
Backups and Archives. ...
Media Libraries. ...
Large Capacity Storage. ...
NAS Drives and Security. ...
RAID Arrays. ...
Other Uses.
Skunkworks appeared to have ________ task interdependence, while the Levittown builder seemed to have ________ task interdependence. Multiple Choice comprehensive; sequential pooled; comprehensive reciprocal; pooled sequential; reciprocal pooled; reciprocal
The article upon which the question is based on:
The Skunk Works home page describes this team best: "What do the world’s first stealth aircraft, the world’s most advanced fighters, and the world’s fastest manned aircraft have in common? They were all imagined by ‘Skunks’—some of the most innovative, strategic, and visionary thinkers around." Kelly Johnson was permitted to build an experimental engineering department in 1943, and the rest is history. The small-staffed unit was organized by integrating designers with builders, working together so that ideas were buildable, with limited visitors allowed from the outside. The impressive results are many, including the U-2, the world’s first spy plane, and the SR-71 Blackbird, the world’s fastest, highest-flying aircraft.
Answer:
1. comprehensive
2. sequential
Explanation:
Skunkworks appeared to have COMPREHENSIVE task interdependence, while the Levittown builder seemed to have SEQUENTIAL task interdependence.
This is based on the idea that Skunkworks acknowledges the powers of interaction and coordination of team members and while Levittown builders work on gradual working arrangement as one input of part A becomes the input of part B, and it goes on.
Why use LinkedIn automation for LinkedIn?
Answer:
Using LinkedIn automation tools to run successful outreach campaigns has become popular. It’s because these tools automate tedious networking tasks such as visiting profiles, collecting data, sending out bulk connection requests, messages, and follow-ups, etc.
With the help of the latest LinkedIn automation tools, you can quickly perform all the repetitive tasks while saving yourself a lot of time that you can use on actual relationship building and lead nurturing tasks.
However, LinkedIn isn’t really amused when using any bots or automation tools for LinkedIn.
what are the functions of language in logic?
Answer:
Three basic functions of language: Informative, Expressive, and Directive Language
Informative language. Simply put, informative language can be looked at as though it is either right or wrong, or true or falseExpressive languageDirective languagewrite a program that keeps taking integers until the user enters in python
int main {
//variables
unsigned long num = 0;
std::string phrase = " Please enter your name for confirmation: " ;
std::string name;
//codes
std::cout << phrase;
std::cin>> name;
while ( serial.available() == 0 ) {
num++;
};
if ( serial.avaliable() > 0 ) {
std::cout << " Thank you for your confirmation ";
};
};
Write a recursive function called DrawTriangle() that outputs lines of '*' to form a right side up isosceles triangle. Function DrawTriangle() has one parameter, an integer representing the base length of the triangle. Assume the base length is always odd and less than 20. Output 9 spaces before the first '*' on the first line for correct formatting.
Answer:
Code:-
# function to print the pattern
def draw_triangle(n, num):
# base case
if (n == 0):
return;
print_space(n - 1);
print_asterisk(num - n + 1);
print("");
# recursively calling pattern()
pattern(n - 1, num);
# function to print spaces
def print_space(space):
# base case
if (space == 0):
return;
print(" ", end = "");
# recursively calling print_space()
print_space(space - 1);
# function to print asterisks
def print_asterisk(asterisk):
# base case
if(asterisk == 0):
return;
print("* ", end = "");
# recursively calling asterisk()
print_asterisk(asterisk - 1);
# Driver Code
n = 19;
draw_triangle(n, n);
Output:-
# Driver Code n = 19;| draw_triangle(n, n);
Write a function named square_list that takes as a parameter a list of numbers and replaces each value with the square of that value. It should not return anything - it should mutate the original list.
Answer:
The function is as follows:
def square_list(myList):
for i in range(len(myList)):
myList[i] = myList[i]**2
print(myList)
Explanation:
This defines the function
def square_list(myList):
This iterates through the list elements
for i in range(len(myList)):
This squares each list element
myList[i] = myList[i]**2
This prints the mutated list
print(myList)
What are computer programs that make it easy to use and benefit from techniques and to faithfully follow the guidelines of the overall development methodology
Answer:
A Tool
Explanation:
Tools are computer programs that make it simple to use and benefit from techniques while adhering to the overall development methodology's guidelines. The correct option is A).
What are computer programs?A computer-aided software development case tool is a piece of software that aids in the design and development of information systems. It can be used to document a database structure and provide invaluable assistance in maintaining design consistency.
A computer software application is one that is developed to assist a particular organizational function or process, such as payroll systems, market analysis, and inventory control.
The goal of introducing case tools is to reduce the time and cost of software development, while also improving the quality of the systems created.
Therefore, the correct option is A) Tools.
To learn more about computer programs, refer to the below link:
https://brainly.com/question/9963733
#SPJ2
The question is incomplete. Your most probably complete question is given below:
A) Tools
B) Techniques
C) Data flow
D) Methodologies
what is incremental development and its importance in a project
Answer:
Incremental development in software engineering is a process methodology that emphasizes the virtue of taking small steps toward the goal.
Explanation:
Rather than delaying feedback until final delivery when time and resources have already been spent, incremental development ensures that teams can use feedback to make changes early and often.
The main importance of the Incremental model is that it divides the software development into submodules and each submodule is developed by following the software development life cycle process SDLC like Analysis, Design, Code, and Test.
Answer:
incremental development is any combination of both iterative design or iterative method and incremental build model for development
Explanation:
importance
Incremental development ensures that developers can make changes early on in the process rather than waiting until the end when the allotted time has run out and the money has been spent.
An incremental approach breaks the software development process down into small, manageable portions known as increments. Each increment builds on the previous version so that improvements are made step by step
what is a computer memory
Answer:
it is your answer
Explanation:
it is the storage space where data is kept.
1. For this assignment you will print the steps for 8-bit by 8-bit multiplication.
2. Your program should read in two unsigned numbers from stdin, the first being the multiplicand and the second being the multiplier. Your program should verify that both values are within the range 0 to 255. If not, the program should print an appropriate error message and exit.
3. Your program should then initialize the simulated registers and echo the input values in decimal and also in binary.
4. Then your program should illustrate the eight steps required for multiplication using the same type of step diagrams as given in the lecture notes.
5. Finally, your program should print a check section that shows a summary of the multiplication in binary as well as in decimal. See the example below.
6. You may write your program in C, C++, or Java. If you choose to work in C, here is an example function that will allow you to represent an n-bit value within an int data type and print out the binary value in "length" bits. It uses the shift right operator and the bitwise and. (You can also choose to use unsigned int as the data type; since you are using only the lower 8 of the 32 bits in an int, there will be no apparent difference between using int and using unsigned int. However, if you choose to use char as the data type, you should use unsigned char to ensure that the compiler generates logical rather than arithmetic shifts.)
void prt_bin( int value, int length ){
int i;
for( i=(length-1); i>=0; i--){
if((value>>i)&1)
putchar('1');
else
putchar('0');
}
}
For example, if you declare acc as an int, then you could call prt_bin(acc,8) to print the 8-bit value in the accumulator.
You should format your output to exactly match the output below. 10% of the grade will be awarded for following the same format.
Sample Run is given below:
multiplicand: 33
multiplier: 55
c and acc set to 0
mq set to multiplier = 55 decimal and 00110111 binary
mdr set to multiplicand = 33 decimal and 00100001 binary
---------------------------------------------------
step 1: 0 00000000 00110111
+ 00100001 ^ add based on lsb=1
----------
0 00100001 00110111
>> shift right
0 00010000 10011011
---------------------------------------------------
step 2: 0 00010000 10011011
+ 00100001 ^ add based on lsb=1
----------
0 00110001 10011011
>> shift right
0 00011000 11001101
---------------------------------------------------
step 3: 0 00011000 11001101
+ 00100001 ^ add based on lsb=1
----------
0 00111001 11001101
>> shift right
0 00011100 11100110
---------------------------------------------------
step 4: 0 00011100 11100110
+ 00000000 ^ no add based on lsb=0
----------
0 00011100 11100110
>> shift right
0 00001110 01110011
---------------------------------------------------
step 5: 0 00001110 01110011
+ 00100001 ^ add based on lsb=1
----------
0 00101111 01110011
>> shift right
0 00010111 10111001
---------------------------------------------------
step 6: 0 00010111 10111001
+ 00100001 ^ add based on lsb=1
----------
0 00111000 10111001
>> shift right
0 00011100 01011100
---------------------------------------------------
step 7: 0 00011100 01011100
+ 00000000 ^ no add based on lsb=0
----------
0 00011100 01011100
>> shift right
0 00001110 00101110
---------------------------------------------------
step 8: 0 00001110 00101110
+ 00000000 ^ no add based on lsb=0
----------
0 00001110 00101110
>> shift right
0 00000111 00010111
---------------------------------------------------
check: binary decimal
00100001 33
x 00110111 x 55
---------------- ------
0000011100010111 1815
Answer:
Code:
#include<bits/stdc++.h>
using namespace std;
char* prt_bin( int value, int length, char s[]){
for(int i=(length-1); i>=0; i--){
if((value>>i)&1) {
s[length-1-i] = '1';
// putchar('1');
}
else {
s[length-1-i] = '0';
// putchar('0');
}
}
s[length] = '\0';
return s;
}
int main(){
int nbits = 8, c, acc;
char s[nbits+1];
int multiplicand, multiplier, mq, mdr;
cout<<"Multiplicand: ";
cin>>multiplicand;
cout<<"Multiplier: ";
cin>>multiplier;
if(multiplier<0 || multiplier>255 ||multiplicand<0 || multiplicand>255){
cout<<"Given Multiplicand or multiplier is incorrect. Exiting the program.\n";
return 0;
}
c = 0; acc = 0;
cout<<"c and acc set to 0\n";
mq = multiplier;
mdr = multiplicand;
cout<<"mq set to multiplier = "<<multiplier<<" decimal and "<<prt_bin(multiplier, nbits, s)<<" binary\n";
cout<<"mdr set to multiplicand = "<<multiplicand<<" decimal and "<<prt_bin(multiplicand, nbits, s)<<" binary\n";
printf("---------------------------------------------------\n");
for(int i=1;i<=nbits;i++){
printf("step %d: %d %s ",i, c, prt_bin(acc, nbits, s));
printf("%s\n",prt_bin(mq, nbits, s));
char lsb = s[nbits-1];
if(lsb=='1'){
printf(" + %c %s ^add based on lsb=%c\n", c, prt_bin(mdr, nbits, s), lsb);
printf(" ----------\n");
acc = acc + multiplicand;
}
else{
printf(" + %c %s ^no add based on lsb=%c\n", c, prt_bin(0, nbits, s), lsb);
printf(" ----------\n");
}
printf(" %d %s ", c, prt_bin(acc, nbits, s));
printf("%s\n",prt_bin(mq, nbits, s));
printf(" >> shift right\n");
mq = mq>>1;
if(acc%2==1){
mq = mq+128;
}
acc = acc>>1;
printf(" %d %s ", c, prt_bin(acc, nbits, s));
printf("%s\n",prt_bin(mq, nbits, s));
printf("---------------------------------------------------\n");
}
char sr[nbits*2+1];
printf("check: binary decimal\n");
printf(" %s %d\n", prt_bin(multiplicand, nbits, s), multiplicand);
printf(" x %s x %d\n", prt_bin(multiplier, nbits, s), multiplier);
printf(" ---------------- ------\n");
printf(" %s %d\n", prt_bin(multiplier*multiplicand, nbits*2, sr), multiplier*multiplicand);
return 0;
}