Code:
Primitive<uint64_t> b = 0xCCCCCCCC00000000; I need to save the first 31 (most important) bits - 7FFFFFFE.
I found this solution in the Internet:
Code:
start = (((b)>>(first)) & ((1<<(((last+1)-(first))))-1)); but in my case for this code:
Code: Primitive<uint64_t> start = (((b)>>(32)) & ((1<<(((63+1)-(32))))-1));
I am working on a project where I need to retrive a double number and store 8 bits of the number in one field and the other 16 bits in another field. the code below gives me an error.
lata= lat>>8; latb = (lat & 0xff);
The error states that & and >> are illegal for double. With this in mind, can I use these on a double. If not what can I do to achieve what I am trying to do?
I am trying to retrieve the first three bits of a number. The code that I am using should work but it isn't giving me the correct result when trying certain numbers. Below is the code I am using:
unsigned short num1, num2 = 0; unsigned short num = 65535// binary 111111111111111 num1 = num && 0x07;// gives me 1 but should give 7(111) num2 = num >>3;//gives me 8191, which is correct
Why I am not getting the first three correct bits(111)?
i want to assign number of bits by a variable in bitset? how to do that? like bitset<4> foo; instead of 4 i want to use some variable and later on by user i want to assign it! boost library or any other library!
List<string> ImageList = new List<string>(); ImageList.Add("Assets/Images/Image_0.jpg"); ImageList.Add("Assets/Images/Image_1.jpg"); ImageList.Add("Assets/Images/Image_2.jpg");
[Code] .....
The problem is that It generates a random number that can be the same as the last time. So I figured out, that I need to save my random number so I can use it later, as a if statement.
If saved number == r then it generates a new number.
how to save my generated number on OnNavigatedFrom method.
In my calculator, I am trying to make it so that you put enter 1 to add, 2 to subtract, 3 to multiply, and 4 to divide. I am facing the issue of making it so that you must enter a number, however instead of it being any number, it must be 1, 2, 3, or 4, and if it is not any of those numbers, you must re-enter the number. Here is a little snippet of my code:
Code:
printf("Please enter 1 to add, 2 to subtract, 3 to multiply, or 4 to multiply: "); while (scanf("%d", &input) != 1) { while (getchar() != ' '); printf("Invalid option. Please try again: ");
In this example there are 3 loops, but what if i want to create e.g. 10 such loops, and program reads a number of loops from a txt? It is needed for checking numbers.
Ok, so I am writing this program with 10 different functions, and one of those functions needs to count how many times 0 appears in a text file. I've done this before, but I am so stumped right now. Should I get the numbers from the 2d array I have, or should I just use the text file here? Here is what I have right now:
int toursMissed(int scores[][COLS]){ int counter; for(counter=0;counter<=96;counter++){ if(scores==0){ counter++; return counter; } }
I have a string - a whole sentence that I want to assign a number to each letter, space, comma and period etc. So all "A's" will have the same number, all "B's" will have another number etc. I don't want to use the ASCII numbers because they all need to be sequential and some of the punctuation isn't. I have put the string into a char array to separate each character out and was thinking about running it through a loop with if statements for each letter and assigning numbers there and then saving the numbers in the order they appear into a list as a string but I keep coming up with errors so I don't know how to do it or if there is a better way to accomplish what I'm trying to do.
I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.
Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.
I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.
int main() { int number; cin >> number; //expecting a number for first line user input for (int i = 0; i < number; i++) { string str;
I am having a problem assigning bits a value of 0. The data is a 16 bit integer the bits greater than the 12th bit have garbage either a 0 or a 1. I would like to assign all bits greater than 12th bit the value 0 no matter what their values are. Whats the best approach.
Using the old fashioned (unsigned) multiplication instruction in x64 assembly multiplies RAX (64 bit register) by a 64 bit register. The answer is stored in RDX:RAX (i.e. the answer is 128 bits). Is there any way, using native c++ to get the value in RDX (higher 64 bits)? One I can think of is: right/(limit/left) e.g. if we are limited to a byte then 97*123 would overflow:
97/(255/123) = 46 times, which is RDX's (if it was one byte) value. But this is too inefficient. Is there a fast way?
If we use bitwise-shift to shift all bits to the right by 2, x is 0:
00000000000000000000000000000000
If we then do a bitwise leftshift on x by 30, do we end up with:
11000000000000000000000000000000 or 00000000000000000000000000000000
In other words, when we perform right shift which clips away the least most significant bits, and then do a left shift, is it possible for those bits to reappear?
I have a double variable and depending on certain conditions I need to set certain bits of an unsigned short Variable. For example, if double var is odd I need to set the 15th bit of the unsigned short variable.
I'm trying to write a program that writes data to a disk in C++ without caring about it's file system. Here is what I can do so far:
#include <iostream> #include <unistd.h> #include <fcntl.h> using namespace std; char buffer[] = "Wow! I'm writing this data to a disk without puttting it into a file!"; int main(){ int Disk=open("/dev/sdb",O_RDWR); write(Disk,buffer,sizeof(buffer)); close(Disk); return 0;}
But this program can only write ASCII characters to the disk. But what if I want to mainipulate bits on the disk, how would I do that?
I am trying to encrypt a plaintext using DES in C. I read about the algorithm and how it works, but when i came to write the code i struggled. :
How to locate the lowest 8-bits in a 64-bit key ?
How to shuffle the plaintext according to the algorithm description ? (I read about bitwise operations, but i still cannot understand how i can use them to transfer for example the 5th bit to the location of the 30th bit)
Left shifting the key would not wrap the bits, so i just bitwise or with a mask that will add the bits that did not wrap around?
I'm working on an assignment where I have to read an image in the PPM format. This format consists of a header that contains the parameters and the rest is raw bits.
I have to work with a modified PPM image that contains a secret message. This message is stored in the first X number of bytes. To decode a single character I would have to look at the lowest level bit of 8 bytes and return that as a character, then repeat this for the length of the message.
The code below is what I have so far, but I do not get the expected output but instead I get smiley-faces.... or other ASCII characters depending on the shift.
char buffer = 0; int MsgSize =(size*8); int nRead = 0; printf("The secret message is displayed below: "); for(i; i<MsgSize; i++) {
I just have a short question! I have an sbyte and I want to convert it to an int, but I do not want a value conversion, just to copy the bits, such that the negative numbers in the sbyte will be their complement in the int (-12 in sbyte -> 244 in int)... How can I do that?las
I was trying to program an decimal to binary converter (8-bits) in C. I am a complete beginner so I tried to put the 1's and 0's of the binary number as they come without reversing the order for beginning. I have seen example on the internet but didn't understand them so I decided to write it as I understood it. So, I typed the code as shown below:
Code: #include <stdio.h> #include <stdlib.h> int main() { int number; int BitNum[8], x;
[Code] ....
The problem with the code is that if binary form has 0s in it then program displays a random number instead of a 0. For example if decimal is 7, it should print out 11100000 but it displays only 111(and some stupid numbers instead of 0). I have tried to solve it but failed.