C++ :: Retrieving First Three Bits Of A Number

Apr 25, 2013

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)?

View 2 Replies


ADVERTISEMENT

C++ :: Retrieve Double Number - Store 8 Bits Of Number In One Field And 16 Bits In Another

May 14, 2013

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?

View 1 Replies View Related

C :: Retrieving SIM Card Number From Dongle Using Program?

Jan 2, 2014

I want to get or view the SIM card number from the dongle (the dongle will b already connected to the computer where the SIM card will be inserted into it) but the coding should be done by C programming / Language.

View 5 Replies View Related

C Sharp :: Retrieving USB Pendrive Vendor ID / Product ID And Serial Number

Sep 15, 2012

I am trying to retrieve the parameters from externally connected pendrive. I have been using WMI to achieve this but not able to separate the pendrive's parameters from the other USB devices (such as USBcamera,USBHub etc) ....

View 2 Replies View Related

C++ :: How To Reverse Bits For A Number

Sep 3, 2013

I am working on a project where I need to reverse bits for a number.

For example, if I have 110111100000000 I need to reverse it to 0000000001111011.

View 19 Replies View Related

C++ :: Saving Specific Bits From 64-bit Number

Jun 24, 2013

I have a 64-bit uint64_t number:

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 get an error: left shift count >= width of type

And even if I change 63 to 62:

Code:
Primitive<uint64_t> start = (((b)>>(32)) & ((1<<(((62+1)-(32))))-1));

I get: error: integer overflow in expression

View 5 Replies View Related

C :: Return Number Of Bits Set To True

Jan 3, 2015

The task is to return the number of bits set to true.Here is my code:

Code:

int cardinalityBS(PBitSet _this) {
int s, counter = 0;
for(s = 0; s < 31; s++) {
counter += _this->bits & 1;
_this->bits <<= 1;
}
return counter;
}

[code]....

The code is not working, since whenever I set _this->bits to a number, it returns me the wrong result.

View 7 Replies View Related

C++ :: Assign Number Of Bits By Variable In Bitset?

Nov 29, 2013

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!

View 1 Replies View Related

C :: How To Show All The Bits Of A Number Using Bitwise Shift Operator

Mar 30, 2013

how to show all the bits of a number using bitwise shift operator....and hence represent the number in 2's complement representation

View 1 Replies View Related

C :: Get Binary Number And Change Its Bits - Calling A Function Not Working

Apr 8, 2013

This code gets a binary number and change its bits. I have a problem with the "bits_up" function . Why this function not working?

Code:
#include <stdio.h>
#include <stdlib.h>
int bits_up(uint first,uint last,int *ptr);
int main(void)
{
uint first,last,bitUD;
int InputBinNumber[4],updatedNum[4];

[Code] ....

View 5 Replies View Related

C :: Calculate Number Of Bits In Type - Incorrect Result In Program

Feb 15, 2014

I have this simple program below:

Code:
#include <stdio.h>
#include <limits.h>
unsigned int rightrot(unsigned int x, unsigned int n) {

/* calculate number of bits in type */

size_t s = sizeof(x) * CHAR_BIT;

[Code] ....

The result it prints is 2684356604 on my 32-bit computer. The result I expect is as follows:
0xFF94 is 0000000000000000 1111111110010100 in binary.

Shift it right by 5:
0000000000000000 0000011111111100

Then take that result in shift it right by 27 (s is 32 and p is 5, so the difference is 27):
1111111110000000 0000000000000000

Now we use bitwise or:
0000000000000000 0000011111111100 | 1111111110000000 0000000000000000 = 1111111110000000 0000011111111100

That in decimal is 4286580732. So how does it come up with 2684356604?

View 2 Replies View Related

C# :: Retrieving Same Records In The Same Row?

Sep 25, 2014

I have the records "File attached"

My query is

from c in JOB_HISTORies join d in DEPARTMENTs on c.DEPARTMENT_ID equals d.DEPARTMENT_ID select new {d.DEPARTMENT_NAME,c.START_DATE,c.END_DATE}

How do i put the record Accounting in the same row to avoid duplication.

View 4 Replies View Related

C# :: DLL Passing And Retrieving Data

Sep 18, 2013

I have a C# program going and want to be able to call the DLL and receive back the data requested through a pointer.Below is the DLL import within my C# code.

Code:

[DllImport("MyTest.dll")]
public static extern int ReadNetwork(Byte[] ROM_ID); Below is the code in the DLL Code: int _stdcall ReadNetwork(unsigned char* Array1)
{
ReadDevice(readBackArray);
for(i = 0; i < 20; i++)
{
Array1[i] = readBackArray[i];
}

[code]....

I've tried changing the return values in the DLL's ReadNetwork() function and that works ok, so I know I'm calling the DLL and it runs ok, but printing the result back is where I'm having the problem.

View 2 Replies View Related

C++ :: Retrieving Data From Txt File

Oct 3, 2013

When i execute the program it gets the right data for the first array but the scound either doesn't work at all or just gets to much data. i've tryed using getline and the "cin" for what the file would be in this case "myfile" there is also one more array that must be retrieved from the file.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code].....

View 4 Replies View Related

C/C++ :: Retrieving Contain Of Array Using Pointer

Nov 30, 2013

I was struggling the last 2 days with this C script supposing to open a list of strings (input as fopen(argv[1])and allowing to access to any element of the list. I created an array *gcm[10000] and a pointer *(*gcm_ptr[10000] = &gcm. However, when I try to list whatever n[i], it always gives me the last entry.

View 4 Replies View Related

C++ :: Retrieving Variables From Text File

Apr 18, 2013

I have a text file config.txt which has:

"red = true"
"blue = false"
"children = 10"

I want to write a code that reads the values of these variables red, blue and children when executing the code.

I have something like this:

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main () {
ifstream Configure;

[Code] .....

I want to read the read the values of red, blue and children in and use them when the program executes.

View 1 Replies View Related

C/C++ :: Retrieving User Input With Getline?

Mar 7, 2015

I'm writing a simple text adventure style program in order to practice C++. I originally used char to get whether the user wanted to go north, south etc, requiring they enter W, A, S, or D, and then I used a switch statement, rather than a bunch of else if blocks to move in the appropriate direction. Last night I started updating the code and wanted to require the user type an actual string like "go north" to move, so I'm in the process of converting it over to getline();.

The way it works is the user will input "go north", and if the string is equal to "go north" it will set a variable to 1, 2, 3, or 4, so I can keep the switch statement. The program compiles but whenever it asks for user input, it always hangs waiting for 2 separate lines of input regardless of whether or not you put a space between your command. The move function is as follows:

void movement() {
bool loop = true;
int roomNorth = 0;
int roomWest = 0;
int roomSouth = 0;
int roomEast = 0;
int dirOption;
string dir = "";

[code]....

I read that it could be an issue with getline and the new line characters, which is why I added the cin.ignore in there...so yea the code will wait for 2 separate lines of input and then always outputs "Invalid direction!" regardless of the input.

View 3 Replies View Related

Visual C++ :: Getting Error While Retrieving Value From ADO Recordset

Jul 21, 2013

I have a vc++ project file which reads data from access 2007 database.

I have successfully declared and opened connectionPtr and recordSetPtr objects.

The follwoing code is giving an error message that "item cannot be found in the collection"

stringVar = (recordSet->Fields->GetItem("[String]")->GetValue()).bstrVal;

If i replace "[String]" with "String" then above statement executed successfully.

How can i execute the above statement with "[String]" without errors?

View 4 Replies View Related

C++ :: Retrieving Extracted Values And Run Time Error

Aug 6, 2014

I have issues for the following piece of code :

Code:
#include <string>
#include <fstream>
#include <iostream>
#include <cstdlib>

[Code] ....

I get errors retrieving the grade values extracted, and then I get a run time fault.

View 3 Replies View Related

C :: Phone Book Saving To File And Retrieving

Jul 14, 2013

I am supposed to make this phone book save to a file and then be able to retrieve it.

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Phonebook_Contacts
{
char FirstName[20];
char LastName[20];
char PhoneNumber[20];
} phone;
}

[code]....

View 4 Replies View Related

C++ :: Retrieving Class Types From File Efficiently

Jun 30, 2014

Suppose your program has many concrete subtypes of Person, and each person will have their own file saved, with their type stored in that file. When reading the files to create the people again (of their proper types), what is the best method to maximize performance (and elegance by shortening the code)? Here is what I have so far.

First I used if statements, which is terrible, and now I've improved the performance logarithmically using std::map. I still suspect there is a better way, especially if there are going to be hundreds of different classes. If you want to test it, you can change the PATH constant to whatever path you want, or just leave it as an empty string, and the files will be created in the same directory as your cpp file. The part I'm trying to improve is pointed out in the comments.

struct Person {
std::string name;
Person (const std::string& newName) : name (newName) {}
virtual ~Person() = default;
};
struct Guy : Person {using Person::Person;};
struct Girl : Person {using Person::Person;};

[Code] ....

View 4 Replies View Related

C/C++ :: Storing And Retrieving Large Amount Of Data

Nov 28, 2012

I have to store large amount of data and retrieve the same data then write into file in C++. Currently I am using vector to store and retrieve. But vector is taking more time to store and retrieve the element. Is any other best data structure to store and retrieve large amount of data in unordered way?

Example code:

int I1 = 700,I2 = 32, I3 = 16;
//declare and resize the vector size
vector< vector < vector < vector<DOUBLE> > > > vPARAM; 
vPARAM.resize(I1, vector< vector < vector<DOUBLE> > >

[Code] ....

View 3 Replies View Related

C :: Retrieving Values That Are Stored To Compact Flash Card

Sep 19, 2013

My specific request is for retrieving values that are stored to a CompactFlash card. I am able to store values (we call them recipes) to the CompactFlash card as .csv file. I just haven't been able to figure out the code to retrieve this information back to the touchscreen.

Code:
// Create a new folder if it doesn't exist
CreateDirectory("/recipes");
//Create the file if it doesn't exist
CreateFile("/recipes/recipe.csv");
//open the file
hfile = OpenFile("/recipes/recipe.csv", 2);

[Code]....

Now with that said, I would like to retrieve these values from the .csv file.

View 7 Replies View Related

C++ :: Assigning Bits A Value Of 0

Feb 12, 2014

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.

View 5 Replies View Related

C++ :: Getting Bits In RDX After Multiply (x64)

Aug 13, 2013

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?

View 4 Replies View Related

C++ :: Shifting Bits Away And Back

Mar 25, 2014

Value x is a 32-bit unsigned integer 3:

00000000000000000000000000000011

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?

View 2 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved