Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > 8+8 = 137 ??

Reply
Thread Tools

8+8 = 137 ??

 
 
Rajesh.Rapaka
Guest
Posts: n/a
 
      08-10-2005
Hi,
I am trying to decode the RLE 16 - bit compression using java.
So here I believe all the data is encoded in 16-bit. so even the face
number should be encoded in 16-bit. using java I am reading it as 2
eight bits A and B. Now I need to add these 2 bits in such a way that I
get the correct value in an 8-bit space.

any ideas?

Thank u in advance,
kind regards,
Rajesh Rapaka.

 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      08-10-2005
On 10 Aug 2005 10:02:30 -0700, "Rajesh.Rapaka"
<(E-Mail Removed)> wrote or quoted :

>number should be encoded in 16-bit. using java I am reading it as 2
>eight bits A and B. Now I need to add these 2 bits in such a way that I
>get the correct value in an 8-bit space.


I presume you mean adding modulo 256.


sum = ( a + b ) & 0xff;

--
Bush crime family lost/embezzled $3 trillion from Pentagon.
Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
http://www.infowars.com/articles/us/...s_rumsfeld.htm

Canadian Mind Products, Roedy Green.
See http://mindprod.com/iraq.html photos of Bush's war crimes
 
Reply With Quote
 
 
 
 
Paul Tomblin
Guest
Posts: n/a
 
      08-10-2005
In a previous article, http://www.velocityreviews.com/forums/(E-Mail Removed)lid said:
>On 10 Aug 2005 10:02:30 -0700, "Rajesh.Rapaka"
><(E-Mail Removed)> wrote or quoted :
>>number should be encoded in 16-bit. using java I am reading it as 2
>>eight bits A and B. Now I need to add these 2 bits in such a way that I
>>get the correct value in an 8-bit space.

>
>I presume you mean adding modulo 256.
>
>
>sum = ( a + b ) & 0xff;


I think he's trying to put two 8 bit values together to make one 16 bit
value, in which case he'd want

sum = a << 8 | b;



--
Paul Tomblin <(E-Mail Removed)> http://xcski.com/blogs/pt/
"You can get anything you want on Alice's NNTP server."
 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-10-2005
Paul Tomblin wrote:
>
> I think he's trying to put two 8 bit values together to make one 16 bit
> value, in which case he'd want
>
> sum = a << 8 | b;


Presumably not if he's stored them in bytes.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
Lee Fesperman
Guest
Posts: n/a
 
      08-11-2005
Paul Tomblin wrote:
>
> In a previous article, (E-Mail Removed)lid said:
> >On 10 Aug 2005 10:02:30 -0700, "Rajesh.Rapaka"
> ><(E-Mail Removed)> wrote or quoted :
> >>number should be encoded in 16-bit. using java I am reading it as 2
> >>eight bits A and B. Now I need to add these 2 bits in such a way that I
> >>get the correct value in an 8-bit space.

> >
> >I presume you mean adding modulo 256.
> >
> >
> >sum = ( a + b ) & 0xff;

>
> I think he's trying to put two 8 bit values together to make one 16 bit
> value, in which case he'd want
>
> sum = a << 8 | b;


At least that makes sense with his subject, assuming he got his hex to decimal
conversion wrong. (8 << 8 | is 0x88 or 136 decimal ... not 137 decimal.

--
Lee Fesperman, FFE Software, Inc. (http://www.firstsql.com)
================================================== ============
* The Ultimate DBMS is here!
* FirstSQL/J Object/Relational DBMS (http://www.firstsql.com)
 
Reply With Quote
 
Tim Tyler
Guest
Posts: n/a
 
      08-11-2005
Lee Fesperman <(E-Mail Removed)> wrote or quoted:
> Paul Tomblin wrote:
> > In a previous article, (E-Mail Removed)lid said:
> > >On 10 Aug 2005 10:02:30 -0700, "Rajesh.Rapaka"
> > ><(E-Mail Removed)> wrote or quoted :


> > >>number should be encoded in 16-bit. using java I am reading it as 2
> > >>eight bits A and B. Now I need to add these 2 bits in such a way that I
> > >>get the correct value in an 8-bit space.
> > >
> > >I presume you mean adding modulo 256.
> > >
> > >sum = ( a + b ) & 0xff;

> >
> > I think he's trying to put two 8 bit values together to make one 16 bit
> > value, in which case he'd want
> >
> > sum = a << 8 | b;

>
> At least that makes sense with his subject, assuming he got his hex to
> decimal conversion wrong. (8 << 8 | is 0x88 or 136 decimal ... not
> 137 decimal.


I make it 0x808.
--
__________
|im |yler http://timtyler.org/ (E-Mail Removed) Remove lock to reply.
 
Reply With Quote
 
Rajesh.Rapaka
Guest
Posts: n/a
 
      08-11-2005
yes,
I am reading them as bytes! and I am this is how i felt is the correct
way of doing it....
byte a, b;
readbytes ab();
short value = b << 8 | a;

in this particular compression technique, we get only values between
-127 and 127.

ie a and b can contain values between -127 and 127. But when i see the
value that i get i get most of them above -127.

I dont think conversion from hexadecimal to decimal is important.

any ideas?

thanks in advance,
regards,
Rajesh Rapaka.

 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      08-11-2005
Hi Rejesh,

Rajesh.Rapaka wrote:
> byte a, b;
> readbytes ab();
> short value = b << 8 | a;


OK, think about, what "b<<8" will do with a *byte*!

Hth,
Ingo

 
Reply With Quote
 
Thomas Hawtin
Guest
Posts: n/a
 
      08-11-2005
Ingo R. Homann wrote:
>
> Rajesh.Rapaka wrote:
>
>> byte a, b;
>> readbytes ab();
>> short value = b << 8 | a;


Doesn't even compile.

> OK, think about, what "b<<8" will do with a *byte*!


Much the same as it'd do to an int.

Think about the representation of negative ints across their 32-bits.

Tom Hawtin
--
Unemployed English Java programmer
http://jroller.com/page/tackline/
 
Reply With Quote
 
Ingo R. Homann
Guest
Posts: n/a
 
      08-12-2005
Hi,

Thomas Hawtin wrote:
> Ingo R. Homann wrote:
>>
>> Rajesh.Rapaka wrote:
>>
>>> byte a, b;
>>> readbytes ab();
>>> short value = b << 8 | a;

>
> Doesn't even compile.
>
>> OK, think about, what "b<<8" will do with a *byte*!

>
> Much the same as it'd do to an int.


Testing... compiling... testing again...

Intersting!

What's the reason, that java does not compile the first one, when it
really compiles the second one without complaining? Why does java treat
byte and int so differently in this case?:

byte b = 42;
b = b << 8; // not OK

int i = 42;
i = i << 128; // perfectly OK


> Think about the representation of negative ints across their 32-bits.


???

Ciao,
Ingo

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange startup connection to 199.239.137.* Sam Firefox 8 07-11-2006 03:50 AM
74-137 =?Utf-8?B?QmVuIEhheQ==?= Microsoft Certification 1 09-06-2005 01:32 AM
Understanding error - Java returned: 137 Manish Hatwalne Java 1 09-03-2004 10:01 AM
Should I disable port 137? zoop Computer Security 4 05-17-2004 07:29 AM



Advertisments