C/C++ :: Converting Number Into Binary Or Hexadecimal Or Octal Using Arrays
Mar 1, 2013
Write a program in c++ to accept a number and convert this number into binary or hexa decimal or octal number according to the user choice using the concept of array.
The program is supposed to convert a two digit hexadecimal number to its binary representation. My code runs without any problems but I do not know how to limit the user's input to two digits only. For example the person can input "1ABC" and the program will give the binary representation and I need it to only accept two digit only like for example "1A".
#include<stdio.h> #define MAX 1000 int main(){ char binaryNumber[MAX],hexaDecimal[MAX]; long int i=0; printf("Enter a two digit hexadecimal number: ");
I'm a games/apps developer and right now I'm developing games/apps for iOS, Android and also PC / Facebook. I've also been working on C++ for some time but since I'm learning it all by myself, I still have some beginner doubts.
Is there any easy way to code a value conversion (for example an octal value to an actual number)?
i m trying to write a code that would convert a each letter from a text to their decimal images . while i was able to write the part of entering the text , i cant do the converting part , i searched all day on the internet and found nothing.
I am new at programming and I have some questions about converting decimal to hexadecimal WITHOUT using .net library. The problem is, that I don't know how to do vice versa. (if you type 1254, program returns 6,14,4. I want programm to return 4,14,6- this is almost hexadecimal number (14 is not converted to "E")). Also the task is, that program has to return value in string form.
static void Main(string[] args) { int a = 0; int result = 0; int n=1000000; int[] array = new int[n]; Console.WriteLine("Insert numbers"); a = int.Parse(Console.ReadLine());
Store the result into an array D of 8 elements. Your program should show the decimal numbers for every binary number. Print screen of 6 answers. This means you should try your program six times with different numbers in every run and show the printed screen result.
I nead to write a program that convert an octal number to decimal number, I thought I did it right but it doesn't work.. I have to use in the first for loop as it is because it is part of the instructions (student homework).
i need to code a function that converts an array of 64 bits into a hexadecimal value, the one is tested gives me correct value except for the last hexadecimal letter.
#include<stdio.h>#define MAX 1000 int main(){ char binaryNumber[MAX],hexaDecimal[MAX]; long int i=0; printf("Enter any hexadecimal number: "); scanf("%s",hexaDecimal);
[Code]...
So this is my current code, is there anyway I can reduce the size and use a main function to ask for input and a call function to do all the conversion and return it? I am confused for the past few days trying to figure it out and finally ended up here. Anyway can I write it as a something like this
Code:
int main() { //ask for user input hexadecimal into here and call a let's say hex2binary() function }
int hex2binary(...) { //an array with dynamic memory, malloc? and convert it and return values }
I don't really need the full code, just a simple instruction on how and where to start.
I'm not the best at C but I'm trying to write a C function that basically opens a text file with assembler language does a syntax error check on it and then converts the binary data into hex.
This is my code so far:
Code:
#include <stdio.h> #include <string.h> int main(void) { FILE*fname; char prompt; char filename[15]; char text[100]; printf( "Please enter the name of the file you wish to open: " );
I'm trying to write a program that converts a decimal number to a binary one. I have most of the program written, but I am having a little bit of trouble. Whenever I enter a decimal number, the program will convert it correctly to binary, however, the last number is not included in the conversion. EX: Converting 37 into binary (0100101) yields 010010 when entered into the program. BTW the program must utilize recursion to achieve this goal.
#include <iostream> using namespace std; void decToBinary(int num1); int main() { int num1;
Now I have the binary numbers printed out in my code, but I don't know how I can covert them into to decimal.
#include <iostream> #include <iomanip> #include <string> #include <cmath> using namespace std; int main() { int numberOfDigits; int numberOfRows; char flag;
I'm fairly new to C++ and programming in general and I'm trying to get a program to check the parameters of a binary string before converting that string to dec values. I have the user input 'num' line 39 - 42, but I want to reuse that same value in the 'void bin_to_dec()' function. Is there anyway I can use the same variable between void functions?
I need to create a generic function that changes from any starting base, to any final base. I have everything down, except my original function took (and takes) an int value for the number that it converts to another base. I decided to just overload the function. I am Ok with changing between every base, but am slightly off when using my new function to take in a string hex value.
The code below should output 1235 for both functions. It does for the first one, but for the second, I am currently getting 1347. Decimal to Hex works fine - It's just the overloaded function (Hex to anything else) that is slightly off.
void switchBasesFunction(stack<int> & myStack, int startBase, int finalBase, int num); void switchBasesFunction(stack<int> & myStack, int startBase, int finalBase, string s);
I'm having trouble converting a 4 digit number into a BCD number, in the program I did below I was able to convert a 2 digit number into BCD, but I do not know how to convert a 4 digit number or how to start it.
#include <cstdlib> #include <iostream> #include <string> using namespace std; int main(int argc, char *argv[])
Code: Complete the program below which converts a binary number into a decimal number. Sample outputs are shown belowComplete the program below which converts a binary number into a decimal number. Sample outputs are shown below.
Sample Output 1:
8-bit Binary Number => 11111111 Decimal Number = 255
Sample Output 2:
8-bit Binary Number => 10101010 Decimal Number = 170
Sample Output 3:
8-bit Binary Number => 101010102 Number entered is not a binary number
#include <iostream> using namespace std; int main() { int num;
I'm trying to write a program that takes input from the user (thats a char) and outputs it to the monitor in hex form.The program is meant to continuously take input from the user then output to the monitor in hex form until an EOF is detected this triggers the program to close.The following code does this except that I get a lower case 'a' at the end of each output.
example:
input from user: ABC output to monitor: 41 42 43 a
I am working on an assignment about converting an integer number to its 2's complement presentation. The binary representation is consisting of a single linked list.
As we all know, the steps of this converting is to taking the reminder of the absolute value, then flipping the 1 to be 0, and the 0 to be 1 in the binary number. And the last step will be to add 1 to the binary number invers.
I wrote a code that implements every thin correctly. However, when I reached the part of adding 1, the program was hanged.
int Absolute; //the first step is to convert the number to the binry reprezentation Absolute = abs (value);// by take the Absolute value of the negative number, then find the while (Absolute !=0) //the binary reprezentation { int res; res= (Absolute % 2); pushFront (res); Absolute /=2 ;