multiplying a number by two without using Arithmetic and Shift operators


 
Thread Tools Search this Thread
Top Forums Programming multiplying a number by two without using Arithmetic and Shift operators
# 1  
Old 12-28-2009
Lightbulb multiplying a number by two without using Arithmetic and Shift operators

Hi All,

Is it possible to multiply a number by two without using Arithmetic and Shift operators?

_Thanks
# 2  
Old 12-28-2009
Maybe number of logical operation can help you... But... what is the purpose? O_o

Thanks, kandrewo
# 3  
Old 12-28-2009
You can add a zero at the end of a string that represents a binary number without a shift operator, so it seems to me it can be done.
# 4  
Old 12-28-2009
Quote:
Originally Posted by Scrutinizer
You can add a zero at the end of a string that represents a binary number without a shift operator, so it seems to me it can be done.
Adding a zero at the end of a string representing a binary number *is* a shift operation.
# 5  
Old 12-28-2009
Tools a whol;e bunch of 'if' statements?

Perhaps accompish the result with a bunch of 'if' or 'case' statements? Without understanding the purpose of the question, seems more a theoretical question. (Or, a question posed by a teacher to get a student to think of other commands?)

if x=1 then y=2
if x=2 then y=4
and so on...
# 6  
Old 12-28-2009
Quote:
Originally Posted by achenle
Adding a zero at the end of a string representing a binary number *is* a shift operation.
Perhaps, but there are no shift operators involved...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multiplying lines of file that contain certain letter by value

I am trying to remove the last letter in a file and then multiply each line (which contained this letter) by 500. This is what I have: 1499998A 1222222A 1325804A 1254556 1235 9998 777 cat /tmp/listzz |gawk '{print $4}'|gawk '{gsub(//, ""); print } This removes the A... (1 Reply)
Discussion started by: newbie2010
1 Replies

2. Shell Programming and Scripting

Creating a loop for multiplying columns

I have 2 files, that look like this: ID SNP1 SNP2 SNP3 SNP4 A1 1 2 0 2 A2 2 0 1 1 A3 0 2 NA 1 A4 1 1 0 2 and this: SNP score SNP1 0.5 SNP2 0.7 SNP3 0.8 SNP4 0.2 Basically, all of the SNP-values are 0,1, 2 or NA, and they each have a score, listed in the second file. The total... (5 Replies)
Discussion started by: kayakj
5 Replies

3. Programming

Multiplying 2D arrays using fork()

HI, i am trying to multiply 2 2D arrays (a,b) using fork. The answer will be at c. Each child have to calculate 1 row of c. The code is right, as i think of it, with no errors but i dont get the correct c array... I think there is maybe a mistake in i dimension ... Anyway, here is the code: ... (16 Replies)
Discussion started by: giampoul
16 Replies

4. Shell Programming and Scripting

Multiplying array element

I am trying to take all the elements of an array and multiply them by 2, and then copy them to a new array. Here is what I have i=0 for true in DMGLIST do let DMGSIZES2="${DMGSIZES}"*2 let i++ done unset i echo ${DMGSIZES2} It does the calculation correctly for the first element,... (7 Replies)
Discussion started by: nextyoyoma
7 Replies

5. Shell Programming and Scripting

Arithmetic (number-based) if condition

Hi Folks I'm looking for help with if statement. I'm reading the file with header (starts with 0 on position 1 in the line) and data (starts with 1 on position 1 in the line). I have to check if the number from header (should be number of data rows) equal actual count of the data rows. ... (4 Replies)
Discussion started by: viallos
4 Replies

6. Programming

problem in multiplying arrays

Hi, this is my code.It's simple : there are 2 2D arrays and the multiplied to C. #include<stdio.h> #include<sys/shm.h> #include<sys/stat.h> #include<stdlib.h> main() { int *A; //A int *B; //B int *C; //C int i,j,x,k,d; int id; ... (17 Replies)
Discussion started by: giampoul
17 Replies

7. Shell Programming and Scripting

multiplying values from two text files

Im very new to programming. But I would like to write a script which extracts and multiply values from 2 txt and output as a new file. Can someone please teach me how to write it? Thank you so much for example File A File B 1 34 1 2 2 13 2 2 3 8 3 3 File C output 1 68 2... (2 Replies)
Discussion started by: crunchichichi
2 Replies

8. UNIX for Dummies Questions & Answers

Arithmetic Operators

Hello, I have a list of 'inputs' and i want to convert those on the second list named 'Desired Outputs', but i don't know how to do it? Inputs Desired Outputs 1 2 94 4 276 8 369 10 464 12 ... (0 Replies)
Discussion started by: filda
0 Replies

9. Shell Programming and Scripting

Multiplying Floats/Decimals

Is there a way that i can get something like this to work: Number=`expr 80 \* 10.69` i.e. To multiply an integer by a decimal or a decimal by a decimal etc...? thanks (10 Replies)
Discussion started by: rleebife
10 Replies

10. Shell Programming and Scripting

Error only when multiplying two numbers

Hi $ a=10 ; b=2 $ expr $a + $b 12 $ expr $a - $b 8 $ expr $a / $b 5 $ expr $a * $b expr: syntax error Any idean why I am getting this error only when multiplying two numbers. Whats the exact syntax? Thanks a lot to all in advance CSaha (5 Replies)
Discussion started by: csaha
5 Replies
Login or Register to Ask a Question