Question on reading one character at a time.

Hi. I am assigned a program where I have to read a series of bits (for example: 01010101). Using this I have to make a "graph out of it". The way I am supposed to make a graph is as follows:
Each bit interval will be represented in the output as a field taht is two characters wide.
The value of the signal is represented using either + (to represent +voltage) or - (to represent - voltage) and is always the second character in the output field.
The first character in the output field is either:
' . ' = to indicate no change from the previous signal value or
' / ' = to indicate a negative to positive transition or else
' \ ' = to indicate a positive to negative transition
Example for input: 01010101 and the output would be . + \ - . - / + \ - . - / + . + \ - / +
The code that I got so far is that I read the input from the command line as a argument which I know is nothing but I would just like to know how to read the character one by one and make a graph which is totally boggling my mind because I have no idea how I can do it. Thank you for your help.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Encoder
     public static void main(String[] args)
          int b = Integer.parseInt(args[0].trim());
          System.out.println("You spit out --> "+b);

Alright I sorta got what you were sayin'. The code that I have now is:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Encoder
     public static void main(String[] args)
          String toEncode = String.valueOf(args[0]);
          StringBuffer result = new StringBuffer();
          char lastChar = toEncode.charAt(0);
          char curChar = '0';
          char lastSign = '+';
          int length = toEncode.length();
          for (int i = 0; i < length; i++)
          curChar = toEncode.charAt(i);
          if (curChar != lastChar)
          if (curChar == '0')
          result.append("\\-");
          lastSign = '-';
          else
          result.append("/+");
          lastSign = '+';
          lastChar = curChar;
          else
          result.append(".");
          result.append(lastSign);
          System.out.println("You spit out --> "+result);
But it doens't work according to what I want it to do. What I need it to do is the following: Lets say we have the input of 01010101, the result we will get is ". + \ - . - / + \ - . - / + . + \ - / +". The reason for this is because of the following: The graph starts on the v all the time. When there is a 0 bit there is no change and when there is a 1 bit there is an inversion of the voltage level so since we started with a 0 bit at v, when we hit 1 bit we would make a inversion to -v and when we hit 0 bit there would be no change. I don't know of what I said is clear to you or not. For this program, what it does for the input of 01010101, the output is
" . + / + \ - / + \ - / + \ - / + ". Thank you very much.

Similar Messages

  • Reading one character at a time

    Hello
    How can i read one character at a time from standard input (System.in) ?
    I have tried to use
    ir=new InputStreamReader(System.in)
    ir.read().
    But this method blocks until it gets a return key pressed before going forward
    Any other solution?

    public static char readChar() {
    int ch;
    char r = '\0';
    boolean done = false;
    while (!done) {
    try {
    ch = System.in.read();
    r = (char) ch;
    if (r == '\r') {
    System.out.println("Not a character. Please try again!");
    System.in.skip(1);
    done = false;
    } else {
    System.in.skip(2);
    done = true;
    } catch (java.io.IOException e) {
    done = true;
    return r;
    Try this as an method and then use it..
    This code will read will be in response untill you hit the return key but will take only the first character....

  • Problem --serial port reading one character at a time

    Hi Friend,
    I reading the serial port  one character at a time ,  i specified it in the "serial bytes to read" option in serial port read examples.
    The problem is ----------i can able to read  the data.
    but only the first character is reading again and again...and "reading string indicator" in the serial port example shows only the first character sent ..only for a single time.since i am reading continously ----aleast the first character should display as many times i running the program
    (i am running the vi by run continous option..........)..
    please help me ....how to read the character one by one.....
    regards
    rajasekar

    Hi jason...
    I can able to read the serial port by 1 byte or 2 byte or 4 byte as i can specify it in the serial port read bytes option..(in visa serial read)..
    I need to acquire 4 bytes of data and pass it to the Math-script node..and save these 4bytes of data in array (1 row and 4 column)..
    And split this array(just like array-indexing.vi) and processing it each each column separately....
    or suggest some method to achieve my task.....please.
    one more thing the math-script node is placed in a while loop.....in order to read sequence of bytes continously.......
    regards
    rajasekar

  • Reading a string one character at a time

    Hi,
    I'm hoping you use SmallBasic for year 10 exam students at my school.  But, I have found a problem I cannot solve.
    I need to be able to read one character at a time from a string (txt file) and convert each char to its ACSII code.
    How do to I read one char at a time from a string to enable processing?
    Thanks for your help.
    Baz 

    Here is an over the top solution that will display the Hex value of the character codes of every character in the file.
    TextWindow.Write("Enter full file name: ")
    filnam = TextWindow.Read()
    contents = File.ReadContents(filnam) 'read the entire file
    TextWindow.Clear()
    TextWindow.WriteLine("File Name: " + filnam)
    TextWindow.WriteLine("Offset: 0")
    col = 0
    row = 5
    TextWindow.CursorLeft = col
    TextWindow.CursorTop = row
    For i= 1 To Text.GetLength(contents)
    ch = Text.GetSubText(contents, i,1)
    chVal = Text.GetCharacterCode(ch)
    ConvertToHex()
    TextWindow.CursorLeft = col
    If chVal < 32 Then
    TextWindow.Write(".")
    Else
    TextWindow.Write(ch)
    EndIf
    TextWindow.CursorLeft = 20 + 2 + (col * 3)
    TextWindow.Write(Text.GetSubText(hexstr,1,2))
    col = col + 1
    If col = 8 Then
    col = col + 1
    EndIf
    If col > 16 Then
    col = 0
    row = row + 1
    If row > 20 then
    TextWindow.CursorTop = 23
    TextWindow.CursorLeft = 25
    TextWindow.Write("< < < Press ENTER to Continue > > >")
    TextWindow.Read()
    TextWindow.Clear()
    TextWindow.WriteLine("File Name: " + filnam)
    TextWindow.WriteLine("Offset: " + i)
    row = 5
    EndIf
    TextWindow.CursorTop = row
    EndIf
    EndFor
    TextWindow.WriteLine("")
    TextWindow.WriteLine("")
    Sub ConvertToHex
    HexValue[0] = "0"
    HexValue[1] = "1"
    HexValue[2] = "2"
    HexValue[3] = "3"
    HexValue[4] = "4"
    HexValue[5] = "5"
    HexValue[6] = "6"
    HexValue[7] = "7"
    HexValue[8] = "8"
    HexValue[9] = "9"
    HexValue[11] = "A"
    HexValue[12] = "B"
    HexValue[13] = "C"
    HexValue[14] = "D"
    HexValue[15] = "E"
    val = chVal
    hexstr = "h" 'Need to force Small basic to concatenate rather than add
    While val > 0
    hexPos = Math.Remainder(val, 16)
    hexstr = HexValue[hexPos] + hexstr
    val = Math.Floor(val / 16)
    EndWhile
    For hi = Text.GetLength(hexstr) To 2
    hexstr = "0" + hexstr
    EndFor
    EndSub
    Enjoy!

  • How to read from a text file one character at a time?

    Hello
    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?
    Lavi 

    lava wrote:
    I wish to read from a text file in a for loop and that on every iteration i read one charachter and proceed to the next one.
    can anyone help me?
    Some additional comments:
    You really don't want to read any file one character at a time, because it is highly inefficient. More typically, you read the entire file into memory with one operation (or at least a large chunk, if the file is gigantic) and then do the rest of the operations in memory.  One easy way to analyze it one byte at a time would be to use "string to byte array" and then autoindex into a FOR loop, for example.
    Of course you could also read the file directly as a U8 array instead of a string.
    Message Edited by altenbach on 06-10-2008 08:57 AM
    LabVIEW Champion . Do more with less code and in less time .

  • How do I get the arrow keys to move one character at a time in the address bar or search box?

    I can no longer get the arrow keys to advance or retard "one character at a time" in the address bar, the search box, or on any form in Firefox. This feature works in other browsers without a problem. The "Home" and "End" keys do not work either. How do I fix this behavior?

    How do I configure the AX to connect to the hub's wireless network? It will only scan one base station Airport Express at a time in the Airport Utility. I think what I am trying to do is use the hub as a router to the two AX's. Is there a specific way to set this up?
    To set up the AX to join a wireless network as a "Wireless Client," using the AirPort Utility, either connect to the AX's wireless network or temporarily connect your computer directly (using an Ethernet cable) to the Ethernet port of the AX, and then, try these settings:
    Launch the AirPort Utility.
    Select the AX.
    If not already connected to the AX's wireless network, go ahead and switch to it when prompted.
    AirPort Utility > Select the AX > Manual Setup > AirPort > Wireless
    Wireless Mode: Join a wireless network
    Network Name: <type in the network name/SSID of the wireless network that you want to join or select it from the pop-up menu>
    Wireless Security: None OR, if you are using security on your wireless network:
    Wireless Security: <Select the appropriate level of security for the existing wireless network: WPA/WPA2 Personal | WPA2 Personal>
    Password: <enter your wireless network security password>
    Verify Password: <re-enter the same security password>
    Click Update to write the new settings to the AX.

  • How do I display font one character at a time?

    Right now the way I present my font is it all appears
    instanenous. I don't know if this is even possible or not, but I
    would like to find a way to have the font be displayed one
    character at a time over the course of a variable amount of
    seconds. For example, some of you might recognize this font
    presentation from the game "Phoenix Wright" for the Nintendo DS:
    Click
    here
    for example.
    That is the font effect I'm trying to capture - where the
    font is presented in a character by character fashion. Now
    obviously I could achieve this by putting a new letter on every
    frame, but let's be realistic - that's not the logical way to do
    it. Does anyone know the code/options involved in making this font
    display stylization logically possible? Bonus points if you know
    how to make the characters mouths move with the sychronized font
    and then stop once the text stops =).

    Place a dynamic textfield on your stage and label it myText.
    In frame one place the following code,to increase the write
    speed lower the value of 100 in the setinterval call:
    myText.text="";
    var dText="My text I want to display";
    var dTmr=setInterval(ShowNextChar,100,0);
    var cPos=0;
    stop();
    function ShowNextChar()
    myText.text=myText.text+dText.substr(cPos,1);
    cPos++;
    if (cPos==dText.length) clearInterval(dTmr);
    }

  • Read one word at a time from a text file

    I want to read one word at a time from a text file as it is done by "scanf &s" function in text based programme. It is not possible by " read from text"  function. Suggest me  function or method to solve this.

    The simplest way is to use the spreadsheet string to array function with the space character as the delimiter.
    Note that this won't work unless there is a space character between the words - it won't work with line feeds / carriage returns between the words but you could always split the string into lines first. You may also want to trim whitespace to remove any other non-visible characters (e.g. tab, line feeds) from around the word.
    If you need something more sophisticated that splits based on whitespace (e.g. tab, new line) then you'll probably need to do something with searching the string for these characters (e.g. using a regular expression) and then splitting them yourself into an array.
    Of course...if you actually want to just read one word at a time from the file rather than just split the file into words (I assumed you meant this), you will need to read the file byte by byte using the low level file IO functions, build a buffer of the bytes and check the character you've read to see if it a space.
    Certified LabVIEW Architect, Certified TestStand Developer
    NI Days (and A&DF): 2010, 2011, 2013, 2014
    NI Week: 2012, 2014
    Knowledgeable in all things Giant Tetris and WebSockets

  • Reading one file at a time using File Adapter

    I am using a File Adapter which polls every minute to read files from a Folder. This process picks up all the files in that folder. What I want to achieve is that the File Adapter should read one file at a time. Is it possible to force it to wait for a few seconds before reading the Next file in the Folder. Or is there a solution to what I am trying to achieve? Any help would be appreciated.

    public static char readChar() {
    int ch;
    char r = '\0';
    boolean done = false;
    while (!done) {
    try {
    ch = System.in.read();
    r = (char) ch;
    if (r == '\r') {
    System.out.println("Not a character. Please try again!");
    System.in.skip(1);
    done = false;
    } else {
    System.in.skip(2);
    done = true;
    } catch (java.io.IOException e) {
    done = true;
    return r;
    Try this as an method and then use it..
    This code will read will be in response untill you hit the return key but will take only the first character....

  • Left arrow key does not go back one character at a time

    on my key pad, I cannot backup "over" characters one space at a time  I am not looking to DELETE, merly to backup one character at a time.  I know I can use the function key along with the arrow key for word at a time jump.  I can jump one character to the right by pushing that key but I cannot do that with my left arrow key.  slight annoyance, but I swear it worked before. . .

    The arrow to open the tab history of the Back and Forward buttons has been removed in Firefox 4 and later.
    Use one of these methods to open the tab history list:
    * Right click on the Back or Forward button
    * Hold down the left mouse button on the enabled Back or Forward button until the list opens
    You can look at this extension:
    * Backward Forward History Dropdown: https://addons.mozilla.org/firefox/addon/backforedrop/

  • Read one record at a time

    Hi !
    One of our Java folks here need at function where he reads one record at at time in id order;
    create table url_recs (id number, url varchar2(4000));
    insert into url_recs values(1,'www.fona.dk');
    insert into url_recs values(2,'www.dr.dk');
    insert into url-recs values(17,'www.ihk.dk');
    select read_rec() from dual; - get id 1
    select read_rec() from dual; - get id 2
    select read_rec() from dual; - get id 17
    select read_rec() from dual; - get id 1 - "no more rows - start all over again)
    select read_rec(45) from dual; - get NULL (no rows with that id)
    select read_rec(1) from dual; - get id 1
    The purpose id for some "round robin" trying to get to some internal URL's.
    Can you give me a hint for creating the function(s)
    best regards
    Mette

    Will successive calls come on the same Oracle session? Or across different Oracle sessions?
    If you're going to call the function multiple times within the same Oracle session, you could store the last value returned in a package variable and select the record whose ID is greater than that value every time the function is called. That's unlikely to do exactly what the Java developer is hoping, though, because the Java calls are likely to bounce between multiple Oracle sessions due to connection pooling. And it'll likely require that the Java developer (or app server admin) adds some code when they get a connection from the pool where they reset the package state. Or it'll require that someone develop a method to keep the Java and Oracle session state in sync.
    Justin

  • How to read one bye at a time

    i need to read one byte at a time from a input file. can someone tell me how to do that?

    FileInputStream istream = new FileInputStream(myFile);
    int read_byte = istream.read();API doc work wonders on issues like that

  • ExtendScript Illustrator - Change color of text one character at a time.

    I'm trying to write code for ExtendScript ToolKit to target Illustrator. I've been writing in JavaScript, but am open to switching to AppleScript if needed. The goal of the code is to change the characters in a text box one by one to the color of the image behind that letter. The end goal is to have the color of the text create the image.
    Basically, I select a character. And lets say that character is at 720x648 (in pixels) in a 24x36 in image. Then I detect the color in the image layer at that location. Then turn the selected character to that color.
    I have encountered two problems, finding a way to have the script detect the color of the picture at a given location (ideally in pixels) and then change that one character to that color.
    So far my code is this, with a color hard coded in for testing purposes since I haven't figured out the detection part yet.
    if ( app.documents.length > 0 ) {
    var doc = app.activeDocument;
    //get text from textbox
    var numChars = 0;
    textArtRange = doc.textFrames[0].contents;
    numChars += textArtRange.length;
    //loop through to select characters one at a time
    for (x=0; x<numChars; x++){
         var selectChar=textArtRange.charAt(x)
         doc.characterStyles.removeAll();
         var charStyle=doc.characterStyles.add("NewOne");
         var charAttr=charStyle.characterAttributes;
         var detectedColor = new RGBColor();   //ideally the detected color would go here. But for now it is hard coded.
             detectedColor.red = 242;
             detectedColor.green = 51;
             detectedColor.blue = 51;
         charAttr.fillColor = detectedColor;
         charStyle.applyTo(selectChar); // I got an error here: "Object expected".
    }//end for loop
    To detect the color, I tried using the following code, but it only works in Photoshop and even there I can't find a way to store that color the way I need to.
    app.activeDocument.colorSamplers.removeAll();
    var pixelLoc = [UnitValue(16) , UnitValue(16)];
    var myColorSampler = app.activeDocument.colorSamplers.add(pixelLoc);
    I have put in so many hours into this and just want to rip my hair out. Any help or guidance anyone can give would be SO appreciated! Thanks in advance!!!

    finding a way to have the script detect the color of the picture at a given location (ideally in pixels)
    there's no native command to do this in illustrator,
    I tried using the following code, but it only works in Photoshop.....
    unless you get extremely lucky (working with matching Object names) photoshop code won't work in Illustrator.
    a possible workaround, clip your text to your image, rasterize it, trace it, you might end up with a solid color per character, where you could read their color.

  • Add one character at  a time from External Text file

    Hi,
    I'm using Flash 8, and I have created a standard Dynamic
    field that pulls the text from an external text file using the
    LoadVars function and it works fine.
    To get the correct effect for the design, I would like to be
    able to create the illusion that the characters are being typed out
    when the page loads as if someone has started typing and also hear
    the "Typewriter Clack" each time a character appears.
    The only place I have found an example is on the Syphon
    Filter Game website which seems to have created the illusion
    perfectly:
    http://www.syphonfilterdarkmirror-thegame.com/en_IE/
    (Check out the bottom right section)
    I could create a Movieclip and add a character each frame
    but, I would like to be able to edit the text when required via a
    text file or even ASP or PHP if neccessary.
    Any help would be grateful.
    Cheers

    or here:
    http://www.actionscripts.org/tutorials/beginner/Scripted_Typerwriter/index.shtml

  • Reading one character from System.in

    Is it possible to read just a single character from System.in without the user having to hit "Enter" to accept the character?
    Thanks.

    Is it possible to read just a single character from
    System.in without the user having to hit "Enter" to
    accept the character?
    Thanks.No, System.in is a stream which only gets things put into it when the user hits Enter. If you want to directly interact with the keyboard (not System.in), then you need a GUI-type of app, or use a 3rd-party API such as you could find if you searched the internet for "java curses".

Maybe you are looking for

  • ERROR (ORA-01002)  when Ioading a table by UPDATE/INSERT

    I get the error message ORA-01002 ( Fetch out of sequence ) when I am loading a table by UPDATE/INSERT. At de Runtime Audit Viewer the process of loading update a number of register, in that case 44.050 and to the left register I get the error messag

  • Old hard drive, New MacBook

    Hi, I have just purchased a new Aluminium MacBook to replace my previous white plastic MacBook. In the old MacBook I had a 250GB with OSX 10.5 from WD which I installed myself however when I put this into the new metal MacBook it just keeps restartin

  • Acrobat 9.5.5 Converting word to PDF

    Hello All, I am having a strange issue on a users machine. When they create a folder and rename it, then put  a word document they want into that folder, they are unable to right click and use the "Convert to Adobe PDF" button. What happens is the fi

  • ITunes not opening with windows 7

    iTunes has stopped working on my sony laptop. I have uninstaed all aspects and reloaded. When you click the shortcut or from main menu nothing happens. Whe you look at properties iTunes is now not compatiable !!!what is going on ! Please please help

  • FaceTime has been working great until today

    It was working fine between my iPad2 (in NC) and my daughter's (in MN). Now it's not working on the 4s or MacBook Pro (no audio or video). Anybody have any guesses what's going wrong.