• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Numeric Promotion

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(1)
Please have a look at the following code snippet :
1: int i = 45678;
2: int j = ~i;
3:
4: System.out.println(j);
Select 1 correct answer:
A. Compilation error at line 2.
B. Prints 45677.
C. Prints -45677.
D. Prints -45679.

Is there any shortcut method to get at the answer ?
(2)
write(0x01234567) is called on an instance of OutputStream, what will be written to the destination of the stream.
Ans given is the byte 0x67 but how? I kno that only lower order 8 bits are written to the underlying sink.
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) ~i is equivalent to -(i+1)
2) Like you wrote, write() writes 1 byte of data to the sink. 1 byte = 8 bits.
In hexadecimal representation - each digit can be represented in binary notation using 4 bits. ex - F is 1111.
 
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic