C convert string to binary
hi I want to convert a string into binary and return it or print it. how do I do that
#include<stdio.h>
#include<string.h>
double dec2bin(char str[100]){
//Converting string to int
int n = atoi(str);
double result = 0, base = 1;
while(n!=0){
result = result + (n%2) * base;
base = base * 10;
n = n / 2;
}
return result;
}
void main(){
char str[100];
printf("Enter a decimal (base 10) number as string: ");
scanf("%s",&str);
printf("The decimal number %s in binary (base 2) is %.0f\n", str, dec2bin(str));
}




C convert string to binary hi I want to convert a string into binary and return...
using assembly 8086, Convert a binary string to decimal. Accept buffered user input in the form of a 16-bit binary string. Convert to signed integer and print to the screen. If the user enters less than 16 bits, or input illegal character return an error message and prompt for input again. Sample Execution: Enter a 16-bit binary number: 100111100101110 The decimal signed integer equivalent is -24996 Enter a binary number: 11001011100 Error! Please enter exactly 16-bits: 100111100101110 Enter a 16-bit...
1. Implement an algorithm to convert binary number into an integer. Binary number is represented as a string. Ex. int n = to_int("01010"); int to_int(const std::string& b) { } 2. Implement an algorithm to convert a decimal number to binary. The return type is string which holds the binary number as string. std::string to_binary(int n) { } 3. Implement a function to check if the number is positive or negative. The function should return true if number is positive. bool...
using assembly 8086 , Convert a binary string to decimal. Accept buffered user input in the form of a 16-bit binary string. Convert to unsigned integer and print to the screen. if the user enters less than 16 bits, you may pad the binary number with zeros on the left. Sample Execution: Enter a 16-bit binary number: 1001111001011100 The decimal unsigned integer equivalent is 40540 Enter a 16-bit binary number: 01100 The decimal unsigned integer equivalent is 12
Quick question, I want to know how to convert decimal numbers to binary number, when i have a number like "472" i can convert that, but i get confused when i have something like "472.45" , does this kind of situation just follow the same rule, I mean, can I just convert 472 first, then put a point and convert 45 as well? or not, please help. And, what happen when I have something like " -0.1" for example? Thanks!
def average_word_length(string): num_words = 0 if not type(string)==str: return "Not a string" if not "A" or not "B" or not "C" or not "D" or not "E" or not "F" or not "G" or not "H" or not "I" or not "J"\ or not "K" or not "L" or not "M" or not "N" or not "O" or not "P" or not "Q" or not "R" or not "S" or not "T"\ or not "U" or not "V" or not...
Hi, I am trying to convert a string vector to a double vector in c++ , but for some reason I am getting this error message. Hope you can help! Thanks error: cannot convert ‘std::string {aka std::basic_string<char>}’ to ‘const char*’ for argument ‘1’ to ‘double atof(const char*)’ double salary = atof(info[x].stringsalary); my code is... void display(vector<Employee_Data>& info){ double total = 0; cout << "id" <<setw(25) <<"first name" <<setw(25) <<"last name" <<setw(25) <<"gender" <<setw(25) <<"department" <<setw(25) <<"salary" << endl ; for(int...
How do I write a C program called binary that takes a single command line argument, and integer, in decimal, and prints out the binary representation of the number with 64 bits. The argument must be stored as a long. Use atol to convert the command line argument. Include a function char *binary(long n, char *b) { ... } that stores the binary representation in the string b with '0's and '1's. It is the responsibility of the calling program...
I need to guess from user (number as string) and convert that into int array. If user put "789" array[0] should be 7. However, since two methods are in different classes and I cannot use constructors (except for main), I have no idea how I can do this. Code should be something like this. import java.util.Scanner; Class Guess { Scanner sc= new Scanner(System.in); public String askGuess(){ String guess = sc.nextLine(); return guess; } Class convert is just showing the concept....
How to return a form of the string in C++?? I know that string function has to return a string like an int function returns an int variable. let's say I have a function named string printCircle(int number). In this function, how to return a form of the string as a circle?
Please help solving these following questions: Convert 18210 into binary (or into hex). Convert 3276810 into binary (or into hex). Convert E7A216 into binary or decimal. Convert 11100101102 into decimal (or into hex). • Understand or code a function that uses default parameters. • Describe or use a group of overloaded functions.• Write a function to find the average of a 1-dim array of floats. • Write a function to multiply two 1-dim arrays together to produce a third array...