• Post Reply Bookmark Topic Watch Topic
  • New Topic

About "Bit Pattern"  RSS feed

 
Charles Cheng
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello~
I am a freshman in javaranch
thank teacher Yang brings me here.

the following is my question..

how to print out the bit pattern of a value in any kind of data type?
like byte,short,int,long,float,duoble etc.

int a=7;
print out "a":
00000000 00000000 00000000 00000111

you are so nice to answer this question...
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Charles Cheng:
Hello~
I am a freshman in javaranch
thank teacher Yang brings me here.

the following is my question..

how to print out the bit pattern of a value in any kind of data type?
like byte,short,int,long,float,duoble etc.

int a=7;
print out "a":
00000000 00000000 00000000 00000111

you are so nice to answer this question...

Hello Charles, and welcome to the ranch.

Hope this helps.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Charles!
Vicken's suggestion will be useful when working with the smaller integral primitive data types. Take a look at a very similar method in the Long class for working with that larger integral type. Also, take a look at the Double class documentation for a method that will help out with those floating point types.
[ December 31, 2003: Message edited by: Dirk Schreckmann ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!