# How to double a value without using * and + operators in C

Page 1 of 1

## 1 Replies - 1605 Views - Last Post: 23 June 2009 - 12:39 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=111454&amp;s=d82f0240a208bb54dcd01bb45d97504b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 johnmcjoel

Reputation: 0
• Posts: 1
• Joined: 23-June 09

# How to double a value without using * and + operators in C

Posted 23 June 2009 - 12:09 PM

I need a logic to double a given no without using + and * operators
Is This A Good Question/Topic? 0

## Replies To: How to double a value without using * and + operators in C

### #2 Tiron

Reputation: 5
• Posts: 26
• Joined: 03-October 08

## Re: How to double a value without using * and + operators in C

Posted 23 June 2009 - 12:39 PM

If it is an int/char, using a left bitshift would double the value, and using a right bitshift would half it.

```int i = 50;
i = i << 1; // i * 2
```

If you shift by 2
```i << 2
```
you would be multiplying by 4 (2 * 2 = 0), and shifting 3 bits would be 8;

This post has been edited by Tiron: 23 June 2009 - 12:40 PM