# Get number from pattern (a,b)?

• (2 Pages)
• 1
• 2

## 19 Replies - 1299 Views - Last Post: 30 May 2012 - 11:27 AMRate 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=281177&amp;s=ac697f54881aa8af8aa3d46e74d79803&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #16 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Get number from pattern (a,b)?

Posted 30 May 2012 - 10:37 AM

Not exactly. If you type a-48, it will mean 97-48 that is 49. As I mentioned earlier also, ASCII value of a is 97. So if you want 2 you type '2'-48 which will give 2. I have used '' because they indicate 2 is char, not int.
EDIT : Now that I am back, let me explain in detail. Since you are typing
```printf("%d",a-48);

```

It tells the compiler to print the integral value of 97-48, since the ASCII value of a is 97. If you want integer 2, either write
```printf("%d",'2'-48);//Note the '2', which tell it is char 2, having ASCII value 50.

```

or
```printf("%d",a-95);//95 because 97-95=2.

```

I see many people have doubt about ASCII value. So is there any tutorial on DIC about the same ??

This post has been edited by aresh: 30 May 2012 - 10:52 AM

### #17 tomas7470

Reputation: 1
• Posts: 54
• Joined: 19-February 09

## Re: Get number from pattern (a,b)?

Posted 30 May 2012 - 11:24 AM

U got me Wrong!!
I was ment that a is a number in char!
like im doing:
```scanf("%c", a);
a = '2';
printf("%d", a-48);

```

### #18 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Get number from pattern (a,b)?

Posted 30 May 2012 - 11:25 AM

Oh sorry. Yup, you are right

### #19 r.stiltskin

• D.I.C Lover

Reputation: 2030
• Posts: 5,430
• Joined: 27-December 05

## Re: Get number from pattern (a,b)?

Posted 30 May 2012 - 11:26 AM

No. 'a' is 97, so if you do this
```printf("%d\n", (int)('a' - 48));
```

it will print 49.

Try it.

But
```char a = '2';
printf("%d\n", (int)(a-48));

```

will print 2.

This post has been edited by r.stiltskin: 30 May 2012 - 11:28 AM

### #20 aresh

• It's a 16-Bit World!

Reputation: 273
• Posts: 4,258
• Joined: 08-January 12

## Re: Get number from pattern (a,b)?

Posted 30 May 2012 - 11:27 AM

Umm r.stiltskin, please look at the previous posts.