Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Reading binary from a file and converting to CHAR

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to read binary from a text file into java - I want to read 8 bits and then convert that to a CHAR.

This is my code:



The problem I have is it's reading in as a number.
This is my output:

going to decrypt
value of answer b4 parsing: 0
value of answer: 17
inside decrypt for printb
this is the output: ◄
value of answer b4 parsing: 17
value of answer: 14
inside decrypt for printb
this is the output: ♫


basically I want value of answer b4 parsing to be : 00001111 (as a string)
value of answer: 00001111 (but as a int not a string)
because i pipe that into a decryption algoritm that takes the 8 bits and decrypts then i can convert back to char.

Any help would be much appreciated.
 
Ranch Hand
Posts: 2410
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see where answer is defined.
 
John Gable
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer is defined at the beginning of the method.

int answer = 0;
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
professionally read, modify and write PDF files from Java
https://products.aspose.com/pdf/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!