C/C++ :: Print Binary Numbers From 0 To M - Size N Bits

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


ADVERTISEMENT

C++ :: Pass Array Of Int And Its Size - Print Out Numbers Above Average

Nov 15, 2013

I am attempting to write a program " that has a function that is passed an array of int and its size, and with that it prints out only the numbers that are above average. "

I have included my code so far, but I am only getting one value as output, and that value seems to be completely off. I keep trying, but I am really stuck.

#include <iostream>
using namespace std;
int average(int values[],int size);
int main(){
int size;
int values[] = {1,2,3,4,5,6};

[Code] ....

Added the floats in the average() function. But there is still a value problem.

View 1 Replies View Related

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 View Related

C++ :: Convert List Of Binary Numbers From A File Into Decimal And Print To Screen

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

Visual C++ :: Text Size In Screen Is Different From Size In Print Preview?

Feb 1, 2013

I must take an old MFC project in VC++ 6.0 and make changes.

The problem is text size in screen is different from size in print preview.

for example with this font

Code:
CFont f50;
f50.CreateFont(100,0,0,0,FW_BOLD,0,0,0,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,"Frutiger LT Std 45 Light");

And this text

Code:
s=_T("Let's try to calculate the size of this text");

and with MM_LOMETRIC map mode

GetTextExtent() returns me:

On screen: (1595,99)
Ink printer + print preview: (1589,100)
PDFCreator + print preview: (1580,100)

comparing with screen size the height is bigger but lenght is smaller. I don't understand.

I can understand that different printers process the fonts in different way and then to have different lenghts. That's not the problem. The problem is I need to simulate in screen the same behaviour i will have on printer because these texts are being aligned in the document, and I don't want to see that the text si aligned different in text than in paper.

What can I do to render the text on screen with the same size I will have on the printer? Print preview is doing it. Should I change the font parameters? is something related with pixels per inch?

View 4 Replies View Related

C :: Decimal To Binary Converter (8-bits)

Sep 9, 2014

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.

View 7 Replies View Related

C/C++ :: How To Write 0 Or 1 To Binary File In Bits Not In Bytes

Aug 20, 2014

How I write a 0s or 1s to binary file in bits not in bytes how can i do that ???

View 2 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 :: How To Make Text File Of Bits Stored In AVI / Binary File

Feb 5, 2014

I need to create a program which could create text files of the bits stored in avi file/binary file. My first requirement is to show 0s and 1s in the text representation . My second requirement is to create an avi file from this text file. I have tried few codings but either they give me error or they not playing the reconverted binary files.

View 6 Replies View Related

C :: Won't Print Numbers Sorted When Use Print Function

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

C++ :: What Size To Use For Reading Binary

Jun 10, 2013

My binary file size is 88200000 bytes, but each element should have 2 bytes. So when I use "infile.read( block , size)" , should I be using the size of the file or number of elements (44100000)?

And should block be resized to the number of bytes or the number of elements?

ifstream::pos_type size;
std::vector<int> block;
ifstream infile(filename.c_str(), ios::in|ios::binary|ios::ate);

[Code] .....

View 1 Replies View Related

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++ :: Print Stars Function - Corresponding To Array Index Size

Nov 24, 2014

I am having trouble getting the stars to output correctly in the printStars function. the final output should look something like this:

#include <iostream>
using namespace std;
int readArray(int input[], int size);
void printArray(int input[], int count);
void printStars(int input[], int size);

[Code] ...

View 3 Replies View Related

C/C++ :: Program To Print Product Of Even Numbers And Sum Of Odd Numbers Between 1 And 30

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

C/C++ :: How To Print Binary Tree

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

C++ :: Print Hexadecimal Strings From Binary

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

C/C++ :: Program To Print Out Binary Value Of 16 Bit Number

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

C++ :: Binary Search Tree Print Function?

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

C++ :: Order Numbers By Size Separated By Commas

Aug 13, 2014

Write a program that prompts the user to enter three integer values, and then outputs the values in numerical sequence separated by commas.

So, if the user enters the values 10 4 6, the output should be 4, 6, 10.

If two values are the same, they should just be ordered together.

So, the input 4 5 4 should give 4, 4, 5.

Code:
#include "std_lib_facilities.h"
int main()
{
cout << "Enter three integers, separated by space: ";
int a, b, c, temp1 = 0, temp2 = 0;
cin >> a >> b >> c;

[Code] ....

My first solution has a bug, so here's the corrected solution, written using only features I have learned in the first three chapters:

Code:
#include "std_lib_facilities.h"
int main()
{
cout << "Enter three words, separated by space: ";
string a, b, c, temp;
cin >> a >> b >> c;

[Code] ....

View 5 Replies View Related

C :: Program To Read Binary Data And Print It - File I/O Error

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

C++ :: Print All The Whole Numbers From 1 To N

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

C++ :: Insert Numbers Into A Hash Table Of Size 10 - Using Linear Probing And Chaining

May 28, 2014

How to approach this? Not very clear on how hashing works..

Insert the following numbers into a hash table of size 10 (ie an array with 0…9 index position) using a hash function h(k)=(k*71+94)%10 and using Linear Probing.

75, 98, 43,1,-56,93,101,34,23

Insert the following numbers into a hash table of size 10 (ie an array with 0…9 index position) using a hash function h(k)=(k*71+94)%10 and using Chaining.

75, 98, 43,1,-56,93,101,34,23

View 2 Replies View Related

C++ :: N Prime Numbers - Print Out And Sum

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

C++ :: Program To Print Sum Of Even And Odd Numbers

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

C++ :: While Loops To Print Even Numbers?

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

C++ :: Program Must Print Out 5 Random Numbers

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







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