• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

Bit Representation

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The bit representation of 4 in 32 bit is
0000 0000 0000 0000 0000 0000 0000 0100
Q. How i will print the bit respresentation of 4 on the console.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Iftikhar,

System.out.println(Integer.toBinaryString(4));
API:
public static String toBinaryString(int i)
Creates a string representation of the integer argument as an unsigned integer in base 2.
The unsigned integer value is the argument plus 232if the argument is negative; otherwise it is
equal to the argument. This value is converted to a string of ASCII digits in binary (base 2)
with no extra leading 0s. If the unsigned magnitude is zero, it is represented by a single zero
character '0' ('\u0030'); otherwise, the first character of the representation of the
unsigned magnitude will not be the zero character. The characters '0' ('\u0030') and '1'
('\u0031') are used as binary digits.
Parameters:
i - an integer.
Returns:
the string representation of the unsigned integer value represented by the argument in
binary (base 2).
 
Mr Iftikhar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks suresh seeram.
 
Mr Iftikhar
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Suresh seeram please tell me can i print the complete 32 bits or not.
Or i have to convert it myself.
Basically i making a applet which is found on
javaranch---->campfires---->Cat and Mouse Games with Bits
Which showing the complete bits representation in 32 bits.
 
On my planet I'm considered quite beautiful. Thanks to the poetry in this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic