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 +...
C Programming Please write a single function and not the whole program Can you please provide...
C Programming Please write a single function and not the whole program Can you please provide comments and explanations for all questions. Thank you Write a single function for the following: void split_date(int day_of_year, int year, int *month, int *day);             day_of_year is an integer between 1 and 366, specifying a particular day within the year designated by the parameter year. Month and day point to variables in which the function will store the equivalent month (1 – 12) and day...
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...
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] =...
C++ function to a string into enum function to a enum into a string check valid...
C++ function to a string into enum function to a enum into a string check valid / loop ( asking a couple of times until answer invaild) For example Enum Fruit ( APPLE, STRAWBERRY, BLUEBERRY, BLACKBERRY) output should be what is your favorit fruit? : strawberry you will have STRAWBERRY. what is your favorite fruite : peach invaild TIA
VBA question, write a function check keyword in a string. Question: Function sentimentCalc(tweet As String) As...
VBA question, write a function check keyword in a string. Question: Function sentimentCalc(tweet As String) As Integer This function should check each word in the tweet and if the word exists as one of the keywords in the positive list or negative list it should impact the overall sentiment value. The positive list and negative list words exist in the keywords sheet. Access the keywords as ranges within your VBA code. The case of the word is inconsequential. For instance,...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT