• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

Byte.parseByte("11111111",2)) question

 
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The byte is signed 8-bit number, but as i found out Byte.parseByte("1111111",2)) will work only with 7 bits, resulting in max positive 127 value. Try to parse "11111111" (8 bit for -1) and you will get java.lang.NumberFormatException: Value out of range.
I wonder why? And how to parse negative bit sequences for Byte (not that it is needed to often, but anyways)?
 
Ranch Hand
Posts: 808
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This function is a little specified. I remember that I worked with it and I noticed that it does not care about bit sign.
 
Ranch Hand
Posts: 99
Android Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because in Byte.parseByte(value,radix) you only specify magnitude of number & in byte 7 digits are for magnitude

for specifying sign of number you have to use '-' for negative

Like this

 
Anastasia Sirotenko
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Anuj Prashar wrote:Because in Byte.parseByte(value,radix) you only specify magnitude of number & in byte 7 digits are for magnitude

for specifying sign of number you have to use '-' for negative

Like this


Thank you, i even didn't try "-1111111" as i thought it was definetely illegal for bit sequence 8)
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Wrapper classes are well documented; why not look at the first hand source you will find most of the answers there.


 
That is a really big piece of pie for such a tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic