Question

In: Computer Science

c++ Please read the whole question and instrucions. The instructor wants a function to convert string...

c++

Please read the whole question and instrucions.

The instructor wants a function to convert string to int to perform the bitwise operations then convert int to string back again to show results.

Question:Write a program that produces the bitwise OR, bitwise AND, and bitwise XOR of the bit strings
1001 0011 1011 and 1111 1010 0000.

Thank you in advance.

Solutions

Expert Solution

#include <iostream>
#include <string>
#include <cstdlib>

int main() {

    std::string input1 = "100100111011 " ;
    std::string input2 = "111110100000";

long int i1 = std::stol(input1);
    long int i2 = std::stol(input2);
long int c = 0;

  
   c = i1 & i2;  
   std::cout << "Line 1 - Value of Bitwise AND is : " << c << '\n' ;

   c = i1 | i2;           
   std::cout << "Line 2 - Value of Bitwise OR is: " << c << '\n' ;

   c = i1 ^ i2;            
   std::cout << "Line 3 - Value of Bitwise XOR is: " << c << '\n' ;
   
        
   return 0;
}


Related Solutions

C++ Please read the question carefully and make sure that the function prototypes given are used...
C++ Please read the question carefully and make sure that the function prototypes given are used correctly for both parts. This is one whole programming assignment so please make sure that it;s answered entirely not just one part. The output example is provided at the end of the question. First , write a program to create an array and fill it up with 20 randomly generated integers between 0 to 10 and output the array. Part 1: Write a function...
Please convert this code written in Python to Java: import string import random #function to add...
Please convert this code written in Python to Java: import string import random #function to add letters def add_letters(number,phrase):    #variable to store encoded word    encode = ""       #for each letter in phrase    for s in phrase:        #adding each letter to encode        encode = encode + s        for i in range(number):            #adding specified number of random letters adding to encode            encode = encode +...
Question 3: C-Strings and pointers (10 pts) [5] The following function appends C-string str2, to C-string...
Question 3: C-Strings and pointers (10 pts) [5] The following function appends C-string str2, to C-string str1. Complete the function using array access, i.e. str1[i], but no pointer access. Note: For both part a) and part b) you may not use any library function calls (e.g. you cannot use strlen, strcat, etc.) // Append strt2 to str1 void my_strcat(char str1[], char str2[]) { //YOUR CODE HERE   } // example of using my_strcat() #include <stdio.h> int main(void) { char my_str1[50] =...
Organic Chemistry II: Please read the whole question and then answer with details and clear typing....
Organic Chemistry II: Please read the whole question and then answer with details and clear typing. NO HAND-WRITYNG PLEASE. Not too long ago "free radicals" and quenching those "free radicals" was a big marketing push. We were told we needed to consume or apply antioxidants (in the marketed mixture of the day) in order to reverse or prevent free radical damage. Please post a short description of an example of where some free radicals might originate and a potential antioxidant...
Write a C program that will read a character string and then encrypt the string based...
Write a C program that will read a character string and then encrypt the string based on one of the 3 different encryption methods. The type of encryption is to be selected by the user. Encryption method 1: Swapping by position. Characters in the array are swapped with the opposite characters based on their position in the string. Example: Input string – apple. Encrypted string – elppa Method: The first character ‘a’ and the last character ‘e’ – swap their...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and...
C++ Please Define a function named "isAscending" that accepts a string as an input parameter and returns "true" if all the characters included in the string are ordered in ascending order of their ASCII codes or the input string is a null string, and returns "false" otherwise. For example, if the string "ABXab" is passed to the function, it returns "true" because the ASCII code of 'B' is greater than 'A', 'X' is greater than 'B', 'a' is greater than...
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary...
There is a C function decodeMorse(const String & string, char message[]). This function examines the binary string and iteratively constructs a decimal value (val) and width of each binary pattern (separated by spaces), until a space or a null character ('\0') is encountered in the string. Once a space or a null character is found, this function should call the assembly code (decode_morse()) to obtain the corresponding ASCII value, for the current val and width, and place the ASCII value...
Write a function that takes a C string as an input parameter and reverses the string.
in c++ Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next character and decrement rear to point to the...
[PLEASE USE C++] Write a function to read values of a number of rows, number of...
[PLEASE USE C++] Write a function to read values of a number of rows, number of columns, 2 dimensional (2D) array elements and display the 2D array in a matrix form. Input 2 3 1 4 5 2 3 0 Where, First line of represents the number of rows. Second line of input represents the number of columns. Third line contains array elements of the 1st row and so on. Output 1 4 5 2 3 0 where There must...
C++ Please read the question carefully and match the output example given at the end! Question...
C++ Please read the question carefully and match the output example given at the end! Question In this project you will implement operator overloading for a two dimensional Vector class. Begin with the declaration of the Vector class on the final page. There are three operators that must be overloaded insertion (​<<​), addition (​+​), and subtraction (​-​). insertion (​<<​): The insertion operator is used to send the values of a vector to an ostream object, if a vector has two...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT