# Problem With Binary Number for SPACE

Page 1 of 1

## 1 Replies - 1417 Views - Last Post: 18 February 2009 - 08:04 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=87421&amp;s=1456d71c95ef3108e4d4fc951b58e91b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 mrfikri

Reputation: 1
• Posts: 22
• Joined: 12-October 08

# Problem With Binary Number for SPACE

Posted 18 February 2009 - 06:48 AM

```	String x;
int z;

byte[] w = x.getBytes();

for(z = 0; z < w.length; z++)
{
String p = Byte.toString(w[z]);
int i = Integer.parseInt(p);
String by = Integer.toBinaryString(i);
if(by == "100000")
{
by = "0100000";
}
System.out.print(by + " ");
}
```

I've a problem with this... i don't know why?... characters will be showed in 7 bits binary number but 'space' will be shown in only 6 bits. why? is it going to change the value if i add 0 in front the binary number of SPACE? if no, how to add it since i couldn't make it in my source code.

Is This A Good Question/Topic? 0

## Replies To: Problem With Binary Number for SPACE

### #2 r.stiltskin

• D.I.C Lover

Reputation: 2032
• Posts: 5,435
• Joined: 27-December 05

## Re: Problem With Binary Number for SPACE

Posted 18 February 2009 - 08:04 AM

Change
``` if(by == "100000")
```
to
```if(by.equals( "100000"))
```

== will be true if the lhs and rhs identifiers are the same object, but false if they are 2 separate objects holding equivalent values..

Quote

i don't know why?... characters will be showed in 7 bits binary number but 'space' will be shown in only 6 bits. why?

The ascii code for SPACE is 32 so it only needs 6 binary digits. The ordinary printable characters (on an English keyboard) have ascii codes 33 - 126 so they require 7 binary digits. Integer.toBinaryString() doesn't append any leading zeros.