C++ :: Print All 64-bit Binary Numbers
Jul 31, 2013
I have a program in c++ to print all the binary numbers that have 64 bits. But the problem is it works only for 30 bits. Beyond that the program does not work possibly because of insufficient space availability.
my code is as below:
// C++ program to generate n-bit binary numbers
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
using namespace std;
// This function generates all n bit Gray codes and prints the generated codes
void generateSequence(int n)
[Code] ....
View 2 Replies
ADVERTISEMENT
Apr 26, 2014
I need writing a program that print binary numbers from 0 to M.
Size N bits.
Ascending or descending order according to user choice.
When the default is M = 8, N = 3
View 5 Replies
View Related
Sep 23, 2014
I am trying to make a program that will convert a list of binary numbers from a file into decimal and print the decimal to the screen. I have no problem doing the conversion, the problem comes up when our teacher wants the input file in a format as such:
3
10110101
11111111
10101010
The first number is supposed to tell the program how many different 8bit strings it is going to have to convert, and then the following lines are those binary numbers.
I am not very experienced with file inputs, and I know how to open files and read lines in.. The problem is, how to say "ok the first line says 3, so now I have to convert the next 3 lines" . I am assuming it is just a simple loop that I am missing....
View 4 Replies
View Related
Nov 17, 2013
I am making a program where the user enters numbers into an array and then a number,x. The array is sorted, then x is inserted into the appropriate place. I wrote my selection sort
Code:
void Sort(int ary[], int size)
{
int temp;
int smallest;
int current;
int move;
}
[code]....
put it wont print the numbers sorted when I use my print function, just the unsorted numbers.
View 1 Replies
View Related
May 20, 2014
I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.
#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!
[Code]...
View 5 Replies
View Related
Jan 14, 2015
I want to print binary tree in this form on screen
1
/
2 3
/ /
4 5 6 7
/ /
8 9 10 11
This is the code for creating Binary Tree:
#include<stdio.h>
struct node
{
int data;
struct node *right;
struct node *left;
};
struct node *root = NULL;
int main ()
{
struct node *child, *temp;
[Code]...
View 12 Replies
View Related
Aug 19, 2013
How to search in C or C++ a hexadecimal patterns within a binary file.
For example:
String1:
Code: 0x44 0x65 0x07
Then, once found, extract those 3 bytes and the next 11 bytes (14 bytes in total).
Finally, from those 14 bytes, print without spaces "bytes 1 to 6", "bytes 6 to 12", and byte "13 to 14".
Then I would like to print last 2 bytes (13 to 14) joined in decimal format.
The output without any conversion would be:
Code:
446507c90688 888000800005 0015
4465072ec918 059173495269 002C
44650700cc01 01811bc90b00 00AB
But the output converting to decimal the last 2 bytes would be:
Code:
446507c90688 888000800005 21
4465072ec918 059173495269 44
44650700cc01 01811bc90b00 171
The sample file is attached, and looks like this:
Code:
06 00 00 80 00 00 00 80 09 3c c9 06 88 88 80 00
80 00 44 65 07 c9 06 88 88 80 00 80 00 05 00 15
37 06 01 00 00 01 00 65 00 00 00 02 00 00 02 00
18 00 00 00 03 00 00 03 00 17 00 00 00 04 00 00
[Code] .....
View 8 Replies
View Related
Sep 22, 2013
Write a program to print out the binary value of a 16 bit number.
Create integers i, count, and mask.
Set 'i' to a hex value of 0x1b53.
Set mask to a value of 0x8000. Why?
print a line to show the hex value of i and then the leader for the binary value like this: Hex value = 1b53 Binary=
Use a for loop to loop 16 times and print 16 digits, using count as the loop counter
To test for each digit value, bitwise and 'i' with 'mask'
when the result for the bitwise and is true, print the number '1'
when the result for the bitwise and is false, print the number '0'
then shift mask one place to the right
print a new line and then quit
Use prtscrn and make a hard copy of the code with the console output.
Extra: use the modulus of count and print a space after every 4th digit to make the binary easier to read
The output should look like this: Hex value = 1b53, Binary= 0001 1011 0101 0011
so far this is what i have
#include <stdio.h>
#include <stdlib.h>
int main() {
int i, count, mask;
// 1B53 0001 1011 0101 0011
// 8000 1000 0000 0000 0000
i = 0x1b53;
[Code] ....
it is telling me that there is an "else" without previous "if", also is the program that I wrote correct?
View 3 Replies
View Related
Nov 2, 2014
1) how come root node is printed when the first call to function goes to left subtree?
2) How it resets to root to go to right subtree from last left tree leaf?
void bst:: printNodes(hwareItem*& root){
if(root){
printNodes(root->left);
cout<<root->barcode<<endl;
cout<<root->description<<endl;
cout<<root->price_per_unit<<endl;
cout<<root->stock<<endl;
printNodes(root->right);}
}
View 19 Replies
View Related
Mar 14, 2013
Objective of this program is to read binary data from a file and print it.
Code:
#include <stdio.h>
void readFile(void);
int main(){
readFile();
return 0;
[Code] .....
But When I Run This Code First It Print "Error." Then Rest Of The File.Say In My File I Have "I AM HUMAN", It Prints "Error. HUMAN"!!
I Cant Figure Out Whats Wrong In The readFile() Function.It seems right to me.
View 4 Replies
View Related
Feb 17, 2012
I did write a print function which the user put a number and then it will print out till that number
the output is correct ,, but is code correct ? or it could be better somehow ?
write a function named print_out that print all the whole numbers from 1 to n. test the function by placing it in a program that passes a number n to print_out , where this number is entered from the keyboard . the print_out function should have type void; it does not return a value. the function can be called with a simple statement:
print_out(n);
PHP Code:
# include <iostream>
using namespace std;
void print_out (int x);
int main () {
int n;
cout << " enter a number : ";
[Code] ....
View 2 Replies
View Related
Mar 3, 2014
Write a c++ program to print out the first n prime numbers and the sum of the first n prime numbers.
View 7 Replies
View Related
Apr 14, 2013
I am writing a program that prints the sum of even and odd numbers and here is my code
#include <iostream>
using namespace std;
const int SENTINEL = -999;
int main() {
int integers = 0;
int even = 0;
int odd = 0;
[Code] ....
Nut now in the output it adds -999 to the odd numbers ....
View 3 Replies
View Related
Feb 12, 2012
i am trying to write a program to get a number from user and then print even numbers as well as 0,2,4 and so on.what changes i should do ?
PHP Code:
# include <iostream>
using namespace std;
int main () {
int n,i;
cout << " Enter number ";
cin >>n;
i = 0;
while ( i%2 == n) {
cout <<i<<" ";
i = i+1;
} system ("PAUSE");
return 0;
}
View 13 Replies
View Related
Feb 10, 2014
The program must print out 5 random numbers, from 1 to 45 and 100 different sequence.. Now I want each number of sequence to be different and not the same....
for example
1,2,3,4,5
6,7,8,9,10
....
...
..
here is my code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int main () {
int xRan1;
[Code] ....
View 2 Replies
View Related
Jul 1, 2014
How to insert 10 different numbers to a BST and print out randomly?
View 2 Replies
View Related
Jan 25, 2015
I am trying to print the prime numbers, so i put the numbers into the vector and then erase the non prime numbers. if i comment the break statement i get runtime error saying out of bound, but if i don't comment it out it prints the primes but it also prints the multiples of 3.
void Eratos( int length, vector< int > &v ) {
int i;
for (i=0; i<length; ++i) {
v.push_back(i);
cout <<v[i];
[Code] ....
View 3 Replies
View Related
Dec 7, 2013
I am currently working on a student records program and I want it to print a '-' after every 3 digits from the Id number that I read from the file(ID number from file doesn't have the dashes). How would I do that to print it with dashes?
Here are my reading functions.
Code:
void Read_Student(Student & Temp , ifstream & fin){
fin >> Temp.FirstName;
fin >> Temp.LastName;
fin >> Temp.Id;
fin >> Temp.Quiz;
for (int i = 0 ; i < 6 ; i++)
fin >> Temp.Test[i];
[Code] ....
Intro To Computer Science C++
SAL 343
JHG 344
John Adams
111223333 100 87 93 90 90 89 91
Willy Smith
222114444 90 73 67 -77 70 80 90
Phil Jordan
777886666 100 80 70 -50 60 90 100
One more thing, I also am having problems with reading last name. If I edited the inout file and had for example John Adams Jr. it would cause huge print problems. When I remove it it prints out perfectly.
View 9 Replies
View Related
Nov 13, 2014
I am having trouble finding out how to space out the binary numbers that I am displaying. Currently they are displaying all as one EX: 10001000
How can I get them to be space out properly like: 1000 1000?
Im guessing its something in my loop. Here's my function for converting to binary:
void DisplayBinary(int num) {
int ctr;
unsigned int mask = 32768;
printf("
The input number in binary is: ");
for (ctr = 1; ctr <= 16; ctr++) {
[Code] ....
View 4 Replies
View Related
May 29, 2013
I'm trying to write a program that prints all of the prime numbers to the screen. I'm getting angry because it only prints EVERY number. I think it has something to do with the bool change not being able to leave the for-loop but how to fix it.
Code:
#import <stdio.h>
#include <stdbool.h>
int main(void){
printf("
The Primes Are: 1");
[Code] ....
View 3 Replies
View Related
Feb 19, 2013
I've written a program which takes a character string and then prints each character vertically so that for instance the string 123 can be written as
1
2
3
no what i need is for all the numbers from zero to the inputted number to print the numbers digits vertically but each number to be printed horizontally so that for instance an input of 11 prints
1 2 3 4 5 6 7 8 9 1 1
0 1
i've made it so that i can print all numbers up to the inputted number vertically; however, i am stuck with a method for making each number print horizontally as described above.
View 3 Replies
View Related
Mar 6, 2015
Coding for- To print all combinations of numbers that can compose a given number..
View 3 Replies
View Related
Nov 5, 2014
I am new to programming in C++, and have got a project on this.
Write a C++ program that accepts three numbers from the user (All are integers):
Such as:
Enter the first mark: 3
Enter the second mark: 25
Enter the third mark: 23
The program should find and print the average of the odd numbers greater than 5 and less than 100.
View 4 Replies
View Related
Mar 30, 2013
/* Task: create a function that determines prime number and use it to print out prime numbers from 0-50: */
Function prototype: Should return a `bool` (because it answers a yes/no question) and should take in a single int (to ask whether it's prime).
- An int greater than 2 is prime if it is not divisible by any number between 2 and itself, not including itself.
- Use this function to print out the primes less than 50. Check it against my list:
2 3 5 7 11 13 17 19 23 29 31 37 41 43 47
#include <iostream>
using namespace std;
int prime(int&x) {
if(x%2==1)
[Code] ....
It is printing out the correct prime numbers but also printing this between each number: 1629974960
View 3 Replies
View Related
Dec 16, 2014
for example having input "12345556asf87" we get "123456asf". I need to do this task with getchar and putchar, and the with strings. My programs aren't working
stream:
char c = 0, c_ = 0;
char flag = 0;
while ((c = getchar()) != '.')
{
[Code]....
View 1 Replies
View Related
Jan 21, 2012
I have an exercise that asks me to print numbers at random from the following set (using only a single statement):
2, 4, 6, 8, 10
Here's my statement:
Code:
cout << (2 + rand() % 9) << " ";
which prints numbers at random between 2 and 10, now I can use the modulus operator in an if...else statement to print only even numbers but the exercise specifically requires using only one statement, can that be done using the conditional operator? and if not then how?
View 10 Replies
View Related