Let variable x be a 32-bit non-negative integer of type unsigned int with an actual value between 1 and 1000. Without using a calculator (and actual arithmetic computations), describe an efficient way to find x * 2^17 represented in a binary form, Using your idea, find the binary representation of the number 537 * 2^17.
.
Multiplying a number by 2, means left shifting it.
for example.
binary of 5 = 101
binary of 5*2 = 10 = 1010 i.e shift 101 to left and add zero at the right.
binary of 5*2*2 = 5*2^2 = 10100 i.e shift 101 left two times and add zeroes at the right end.
Here below i've provided the code to do this task.
**** CODE STARTS HERE ****
#include <bits/stdc++.h>
using namespace std;
void print_binary(int x, int n){
int flag = 0 ;
for (int i = 31; i >= 0; i--) {
int k = x >> i;
if (k & 1){
cout << "1";
flag = 1;
}
else if(flag == 1){
cout << "0";
}
}
while(n--){
cout << "0";
}
}
int main() {
unsigned int x, n, ans;
cout<< "Enter the value of x: "; // Here enter 537
cin >> x;
cout << "Enter the power of 2 to be multiplied: "; // Enter
17 if to be multiplied by 2^17
cin >> n;
cout << "The calue in binary is: "
print_binary(x, n);
return 0;
}
**** CODE ENDS HERE ****
Let variable x be a 32-bit non-negative integer of type unsigned int with an actual value...
Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...
Give an informal description (in plain English) of a Turing machine with three tapes that receives as input two non-negative integers x and y, and returns as output the integer xy. Integers are represented as binary strings.Start of the computation: The first tape contains the binary representation of x and its head is on the rightmost symbol of x. The second tape contains the binary representation of y and its head is on the rightmost symbol of y. The third...
5. Let X be a non-negative integer-valued random variable with positive expectation. Prove that (Hint: Use the following special case of the Cauchy-Schwarz Inequality: First, make sure you see why this is a special case of the Cauchy-Schwarz Inequality; then apply it to get one of the inequalities of this problem.)
5. Let X be a non-negative integer-valued random variable with positive expectation. Prove that (Hint: Use the following special case of the Cauchy-Schwarz Inequality: First, make sure you see...
lab3RGB.c file:
#include <stdio.h>
#define AlphaValue 100
int main() {
int r, g,b;
unsigned int rgb_pack;
int r_unpack, g_unpack,b_unpack;
int alpha = AlphaValue;
printf("enter R value (0~255): ");
scanf("%d",&r);
printf("enter G value (0~255): ");
scanf("%d",&g);
printf("enter B value (0~255): ");
scanf("%d",&b);
while(! (r<0 || g<0 || b <0) )
{
printf("A: %d\t", alpha); printBinary(alpha); printf("\n");
printf("R: %d\t", r); printBinary(r); printf("\n");
printf("G: %d\t", g); printBinary(g); printf("\n");
printf("B: %d\t", b); printBinary(b); printf("\n");
/* do the packing */
//printf("\nPacked: value %d\t", rgb_pack); printBinary(rgb_pack);printf("\n");...
5. Let X be a non-negative integer-valued random variable with positive expectation. Prove that E X2] (Hint: Use the following special case of the Cauchy-Schwarz Inequality: First, make sure you see why this is a special case of the Cauchy-Schwarz Inequality; then apply it to get one of the inequalities of this problem.)
5. Let X be a non-negative integer-valued random variable with positive expectation. Prove that E X2] (Hint: Use the following special case of the Cauchy-Schwarz Inequality: First,...
5. Let X be a non-negative integer-valued random variable with positive expectation. Prove that E X2] (Hint: Use the following special case of the Cauchy-Schwarz Inequality: First, make sure you see why this is a special case of the Cauchy-Schwarz Inequality; then apply it to get one of the inequalities of this problem.)
5. Let X be a non-negative integer-valued random variable with positive expectation. Prove that E X2] (Hint: Use the following special case of the Cauchy-Schwarz Inequality: First,...
Undecimal to decimal&decimal to undecimal
#Your code here
Thank you!
Binary-to-Decimal In a previous lab, we considered converting a byte string to decimal. What about converting a binary string of arbitrary length to decimal? Given a binary string of an arbitrarily length k, bk-1....bi .box the decimal number can be computed by the formula 20 .bo +21.b, + ... + 2k-1. bx-1- In mathematics, we use the summation notation to write the above formula: k- 2.b; i=0) In a program,...
C++ requirements The store number must be of type unsigned int. The sales value must be of of type long long int. Your program must properly check for end of file. See the section Reading in files below and also see your Gaddis text book for details on reading in file and checking for end of file. Your program must properly open and close all files. Failure to follow the C++ requirements could reduce the points received from passing the...
This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...
1. Implement a tostring() member function. This function will return a string representation of the LargeInteger. You should probably used string streams to implement this function. Note that the digits of the large integer are stored in reverse of their display order, e.g. the 1's place (100 ) is in index 0 of digits, the 10's place (101 ) is in index 1, etc. 2. Implement a second constructor for the LargeInteger. This constructor will be used to construct a...