Getting bits of a byte

I'm searching for an easy methode to get a bit of a byte. Is it possible to act on a single bit of a byte maybe in a way like the following:
byte myvar = (byte) 15;
boolean mostsig = mybit.BIT7;
and upside down
byte myvar;
myvar.BIT6 = true;
I searched the whole day but fund only solutions for integers. I don't want to go a long way by converting to an int and then to a String of bits ....
thx very much [alibaba]

thx I allready read the BitSet thing but it wasn't helpful because there is no function implemented to load a whole byte inside. But the bitmasking was good
thank you!!!
have fun [alibabashack]
don't wonder about alibabashackweb
alibabashackweb = alibabashack
I just had some probs I think a bug in the forum caused this. now I have an account and two screen names^^

Similar Messages

  • 32 bit integer to byte

    Hi All,
    i convert 32 bit integers to bytes , and this works fine with a small problem.
    when i print the bytes i get 0 for 00 and A for 0A and so on, i use the method below to put the "0" , but it isn't the best way to handle with bytes
    String  tChar;
    String tOut;
    for(int id = 0; id < mSendByteArray.length; id++){
    tChar=Integer.toHexString(mSendByteArray[id] & 0x0FF).toUpperCase();
    tOut = (tChar.length() < 2 ? "0" + tChar : tChar).toUpperCase();
    System.out.println(tOut);
    }can anybody please help
    best regards

    Create an int from the bytes and format that as a hex string, adding on as many extra zeros as necessary?
    You could always build up a char[8] and fill it by bit-shifting and masking your int to fill it with 0-F values. This is essentially all Integer.toHexString does and it's not so special that you couldn't just reimplement it in a utility method yourself.
    Extending NumberFormat to do this would be a tidy approach but perhaps not "optimal".
    Hope this helps.

  • Trim a single bit from a byte?

    OK so im a mechanical guy, not a programming guy so lets start there.  I just learned how hexadecimals work and have limited experience in LABview.  I have been searching this topic for days, maybe its just my vocabulary but I havent found anything.
    I need to analyze a signal coming from a CAN system.  I dont have the can device yet but I'm accessing position sensors on the system.  They come in as 8-bit hexadecimal messages.  I am currently simulating this message as a string in LABview so i can get one part of my program ready.  The manufacturer has given me example code that requires concatenating two bytes but I only need 3 of the bits to be concatenated. (one needs the last bit trimmed and the other 2 need the first bit trimed.)  I have already concatenated the two bytes necessary but cannot figure out how to get rid of an individual bit.  I need to do this as hex values to get the proper measurements.  I know my programming grammar is probably a bit off so let me give you an example.
    Example String of Hex Values
    03 23 F6 21 B4 C4 74 F6
    The first sensor requires bits 3 &4 (21 & b4)
    In this case they are required to be in the order 4,3 and drop the first bit to receive 421 as the needed hex value.  So far I have made an input string to simulate the incoming CAN message with that 8bit hex values.  I then use string subset to isolate the individual bytes and finally concatenate to get them in the correct order and end up with B421.  I cannot figure out how to drop the "B" bit or replace with a zero.  I can only replace the full byte.
    Is there an easier way to do this.  I plan to use the example VI to receive the CAN messages which outputs to a string, hence why I am using strings.
    Thank you in advance for the help.  I am going crazy trying to figure this out.
    Also if any other details are necessary please let me know

    jpc335 wrote:
    I was told by the manufacturer that the 3 bit hexadecimal string can then be converted into usable numbers.  So if its faster/easier to replace the first byte with a 0 or turn it into a 3 bit hex string.  Either will work.
    You want to break yourself of this misuse of bit ASAP.  A bit is a single 1 or 0.  Hex requires 4 bits to find the values.  The purpose of hex is to reduce the number of bits you must write out so things are easier to read.
    0000 - 0
    0001 - 1
    1010 - A
    1111 - F
    When you have two hex digits, you have 8 bits, or a byte.  You're talking about two entirely different conversations when you ask how to extract a bit or a byte.  It's generally easier to pull out the byte.
    You'll also want to be careful with words like "third."  You're not looking for the third byte.  You're looking for the fourth byte.  WIth zero-indexing, it could be the byte at index 3.  But, you're creating confusion when you use third to mean fourth.
    In terms of solving your problem, it sounds like you're going to have a string of characters.  At this point, it's relatively meaningless to view them as hex.  The environment sees them as a string and will operate on them as such.  You can use string parsing VIs to remove the parts of the string you don't care about.  If the format always looks like what you showed us, it wouldn't be hard to traverse through the string by looking for spaces.  From there, you'd need to worry about whether you need the values to be in a numeric type or if string is still sufficient.  But, you should handle splitting off only the string values representing the two bytes you're worried about.  Once you can do that, you can take the next steps.

  • How to get the number of bytes stored in a field?

    Hi Guys,
    How can i get the number of bytes stored in a field.
    I tried using DESCRIBE FIELD, But here i am getting the length from the definition.
    i.e 8 bytes for string and for character value is from definition.
    Prompt replies will be Awarded with full points:-)
    Thanks,
    vinod.

    u see this : http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f2e5446011d189700000e8322d00/frameset.htm
    http://help.sap.com/saphelp_nw04/helpdata/en/cf/21f2e5446011d189700000e8322d00/frameset.htm
    Madhavi

  • How to get the number of bytes at TCP port

    Hi all,
    How to get the number of bytes to read at the TCp port...as someone had suggested in some forum we do read the number of bytes first and then pass this...
    but we get a problem when we have FF data in this...because then it sends 2 FF data...and cause of this we skip the last data...is there any solution for the same?

    Hi
    In LabVIEW you don't have the same property as in serail port.
    You havn't "Byte at TCPIP port".
    if you developp a protocol, one soltion, is to send the size to read.
    Ingénieur d'Application / Développeur LabVIEW Certifié (CLD)
    Application Engineer / LabVIEW Certified Developer (CLD)

  • How to get more than 256 bytes data

    hello.
    I use Schlumberger 32K Card�iJava Card 2.1�j.
    Please tell me how to get more than 256 bytes data from the applet in the card!!
    According to JCRE specification, need to use Get Response Command.
    What is Get Response command?
    Do I have to write processing of Get Response command to an applet?
    Or JCRE processes Get Response command?
    If knows, please tell me about!!
    Thanks.

    Thanks for your response!!
    I understand that I have to write processing of Get Response command to an applet.
    But case of Schlumberger 32K card, when host send Get Response command to an applet, card reply 6F-00!?
    I'm investigating now, and it seems that response is returned before applet processes Get Response command(CLA = 00, INS = C0).
    Do JCRE perform the process of Get Response command?

  • How to get folder size in bytes

    Hi all,
    Is there a easy way to get folder size in bytes?  I don't want to check each file in it and then add them up.
    Thanks for any help.
    Anne

    Years ago, I found my home PC was lacking disk space and could not exaplain where all of the space went.
    At the same time I was teaching myslef how to use the Picture control and Windows did not allow you to check the size of a folder and it sub-folders. So I used that situation to learn about the picture control and LV at the same time.
    It worked and ran but very slowly.
    Soon after Greg McKaskle was putting together the first version of "The Good The Bad and The Ugly" and was looking for fodder to beat up. I offered and he accepted. When the time came for the presentation, my code was chosen as "The bad" since I had not learned how to do a cluster sort at that time so I wrote my own version of a bubble sort (the VI presents a Pie Chart of disk usage and clcik on the sectors of the Pie Chart allowed you to drill down so I hd to sort by sizes).
    So why am I telling you this long boring story?
    That code is attached for you to look at laugh and tell me how dumb I was.
    Feel free to beat me up. It can't be any worse than the abuse I got from Greg (I felt like I was being raped).
    Have fun!
    Ben
    Code is probably 6 or thereabouts. "Disk_Utility" is top level. Remember this is an example of how NOT to code.
    Ben Rayner
    I am currently active on.. MainStream Preppers
    Rayner's Ridge is under construction
    Attachments:
    DIsk_Pie_Utility.zip ‏162 KB

  • How to get image size in bytes

    i have to get image size in bytes and accessing image from the a folder
    Thanks in advance

    If it's going to be accessed as a file on the filesystem, you can use java.io.File.length() to get the size in bytes.
    In other situations...it depends on what you're doing.

  • What is the best way to get an image as byte array

    Hi, I have an iamge stored in a file (jpg or gif) and I want to get the pixels as byte array. The image will be black and white only (tresholded) so byte will be enough to hold all the colors. What I'm doing now works but it just doesn't look good so I think there must be a better way.
    Thanks!

    just in case somebody else tries to do the same. When
    you first get the jpg image with the JPEG decoder and
    store it in a BufferedImage you can't get the pixel
    samples as byte arrays. You'll have to get them first
    as int[] and then make your own byte[].Anything coming in as pixels tends to be highly organized. You have this image array right. Now, how is it organized you must ask yourself? Then you can access it, bytewise or bitwise!

  • Javax.crypto.spec.SecretKeySpec seems to ignore the last bit in every byte

    Hi All,
    I am having a problem with the SecretKeySpec class in JCE 1.2.2. I am using DES as algorithm, and a 8 byte long key. I am passing a hex array of 16 characters (each 2 representing a byte) and create a byte array of length 8 from that hex array. For example, the following "A12C3D4E5F6A7B8E" is equivalent to a byte array, having the values of the bytes (in signed byte) [-95, 44, 61, 78, 95, 106, 123, -114]. It works perfectly but what I observed is, if one of the bytes looks like "5E" and I change it to "5F," the code still works, the encrypted text using the key created with "5E" key is decrypted correctly using the "5F" key. It doesn't work if the byte is "E5" and I change it to "F5," and this led me to think that the SecretKeySpec implementation ignores the last bit of every byte (uses just the high 7 bits.)
    Anybody came accross this before? Any help appreciated.
    THanks,
    Marius

    As I said, "every implementation I'm aware of ignores them". They're not used during en/decryption, they exist only to provide (marginal) evidence that the key might have been mangled in-transit. Many implementations just skip that step. Note that i'm not saying this is a good thing - it's just been my experience.
    The 64-bit quntity you're playing with is NOT "the key" - the DES key is the 56 bits that do not include the parity bits. Ignoring the parity-bits doesn't yield more keys that will do the same decryption, since the parity bits aren't used by DES itself.
    The net? Don't worry about it. It's the 56 bits that are the important ones.
    Grant

  • How to get the string's byte length?

    I have some string,I want to get the string's byte length,how
    can do it?
    for example:
    <cfoutput>#len('hihi,这是测试')#</cfoutput>
    output is 9
    I want to get the byte length is 14, how can i get it?
    Thanks.

    >> Fair cop. I didn't realise that asc() returned the
    codepoint rather than the
    > actual character code.
    >
    > and what would be the difference?
    Oh, sorry, whatever the term is (I'm crap with jargon). The
    value returned
    by asc() for those chars was only two bytes (ie: four hex
    digits). I
    didn't realise there was more to it than that, and that
    2-byte value maps
    to some other THREE byte value. I need to do some reading...
    > that's what both cf & java counted as the length.
    CHARACTER length, sure. No-one's disputing that. On the other
    hand,
    no-one's asking about it, either.
    > by adding a BOM you've already effected the encoding,
    which may or may not
    > match the original. so you still don't know how many
    bytes were in the original
    > string.
    [groan]
    Yes, that's a reasonable strawman there. I was only putting
    it in a file
    so I could save it and check the number of bytes occupied by
    the data.
    Clearly... CLEARLY... the OP is not asking for a character
    length of that
    string. They've said as much.
    I copy and pasted the string from their post, and used it as
    a
    demonstration of how "nine" is not the right answer for the
    BYTE LENGTH of
    that string. Whether or not the original string was UTF-8,
    UTF-16 or
    special-marmoset-encoding, it almost certainly was NOT in a
    fictitious kind
    encoding in which each of those particular characters only
    occupied one
    byte each, which would mean that "nine" is the correct answer
    to the
    question.
    When I copied those characters from either the web browser
    for from my
    text-based news agent, notepad identified them (and rendered
    them
    correctly) as UTF-8, so I'm fairly confident they ARE UTF-8.
    Of course
    this could be down to some intermediary encoding (pasting
    them in to the
    original posting, for example, via some encoding-transforming
    mechanism),
    but Occam's Razor suggests the original question was from a
    UTF-8 POV.
    But maybe we should quit speculating and ask the OP. Unless
    they've
    buggered off in despair of how drawn out all this is getting.
    For which I
    would not blame them.
    Adam

  • HT1277 i have cleaned out my inbox out box and trash and got rid and i am still getting bounced message notification "bytes in the mailbox" what else shd i do

    i have cleaned out my inbox, out box , and i am still getting bounced message notification "bytes in the mailbox" what else shd i do

    i have cleaned out my inbox, out box , and i am still getting bounced message notification "bytes in the mailbox" what else shd i do

  • How to get audio data in (bytes)

    is there a way to get the bytes of a wav file using jmf (not java sound)
    cause i need to draw the waveform of the audio file (any ideas about that 2)
    thanx in advance for replying.

    well it's a bit complicated u have to know the sample size and the byte sex (bigindian or smallindian) ,the following code is taken from SUN javasounddemo
    it can be downloaded from the SUN site.( i recommend downloading it in order to understand the entire code)
    public void createWaveForm(byte[] audioBytes) {
    lines.removeAllElements(); // clear the old vector
    AudioFormat format = audioInputStream.getFormat();
    if (audioBytes == null) {
    try {
    audioBytes = new byte[
    (int) (audioInputStream.getFrameLength()
    * format.getFrameSize())];
    audioInputStream.read(audioBytes);
    } catch (Exception ex) {
    reportStatus(ex.toString());
    return;
    Dimension d = getSize();
    int w = d.width;
    int h = d.height-15;
    int[] audioData = null;
    if (format.getSampleSizeInBits() == 16) {
    int nlengthInSamples = audioBytes.length / 2;
    audioData = new int[nlengthInSamples];
    if (format.isBigEndian()) {
    for (int i = 0; i < nlengthInSamples; i++) {
    /* First byte is MSB (high order) */
    int MSB = (int) audioBytes[2*i];
    /* Second byte is LSB (low order) */
    int LSB = (int) audioBytes[2*i+1];
    audioData[i] = MSB << 8 | (255 & LSB);
    } else {
    for (int i = 0; i < nlengthInSamples; i++) {
    /* First byte is LSB (low order) */
    int LSB = (int) audioBytes[2*i];
    /* Second byte is MSB (high order) */
    int MSB = (int) audioBytes[2*i+1];
    audioData[i] = MSB << 8 | (255 & LSB);
    } else if (format.getSampleSizeInBits() == 8) {
    int nlengthInSamples = audioBytes.length;
    audioData = new int[nlengthInSamples];
    if (format.getEncoding().toString().startsWith("PCM_SIGN")) {
    for (int i = 0; i < audioBytes.length; i++) {
    audioData[i] = audioBytes;
    } else {
    for (int i = 0; i < audioBytes.length; i++) {
    audioData[i] = audioBytes[i] - 128;
    int frames_per_pixel = audioBytes.length / format.getFrameSize()/w;
    byte my_byte = 0;
    double y_last = 0;
    int numChannels = format.getChannels();
    for (double x = 0; x < w && audioData != null; x++) {
    int idx = (int) (frames_per_pixel * numChannels * x);
    if (format.getSampleSizeInBits() == 8) {
    my_byte = (byte) audioData[idx];
    } else {
    my_byte = (byte) (128 * audioData[idx] / 32768 );
    double y_new = (double) (h * (128 - my_byte) / 256);
    lines.add(new Line2D.Double(x, y_last, x, y_new));
    y_last = y_new;
    repaint();

  • How can a get() return the POF bytes without deserializing?

    Is it possible to perform a get() from the cache without deserializing an object, anmd instead request the POF bytes directly?
    The use case is a middle tier server that is an extend client. It supports legacy downstream clients that should receive part or all of the byte[] directly.
    The objective is to be able to transfer data and avoid a deserialization step:
      cache ---(POF)---> mid tier extend client ---(POF)---> downstream client This would need to work from a .NET or C++ extend client.
    Thanks,
    phil

    Hi Phil,
    This can be easily achieved using an entry processor, as long as you want to return the whole value. Something along the lines of the following should do the trick:
    public Object process(InvocableMap.Entry entry) {
        return ((BinaryEntry) entry).getBinaryValue().toByteArray();
    }The things are a bit trickier if you want to extract a single property only from the value but it is doable:
    public Object process(InvocableMap.Entry entry) {
        BinaryEntry binEntry = (BinaryEntry) entry;
        PofValue value = PofValueParser.parse(binEntry.getBinaryValue(), (PofContext) binEntry.getSerializer());
        AbstractPofValue property = (AbstractPofValue) value.getChild(index);
        return property.getSerializedValue().toByteArray();
    }Sorry I don't have time to test the code above, but off the top of my head I don't see a reason it shouldn't work.
    Regards,
    Aleks

  • How to use SET BIT and GET BIT in ABAP Programming

    Hi,
    Our team is currently working for an Upgrade  project which is using a tool automatically upgrades when we supplly the code. fine, But now the requirement is , we need to write different test cases for the available key words in ABAP. Now we r looking for the usage of  " BIT ", keyword. so , kindly provide any program or code using this key word.
    Please find the description Provided and give some relative ABAP code to satisfy the given description.
    The data object byte_string must be byte-type. The statement reads the bit at the bit position BITPOS of the variable byte_string and assigns its value to the variable val. A default mode can be specified if required *
    Thanks & Regards,
    P.N.Kumar.

    What on earth are you testing? That ABAP still works? I think SAP might have run that through rigourous testing themselves.
    If you want sample code, why not read the ABAP help, and work some out for yourself?
    matt

Maybe you are looking for

  • Error when printing work order with iw32

    Hello all, When i was printing work order using IW32, the order success to be saved but it can't be printed. And i get this error message : Express document "Update was terminated" received from author ... i check with T-Code SM13, and i found error

  • Latest Premiere and Media encoder CC update shuts down

    Latest Premiere and Media encoder CC update shuts down when you load saved file or try to export to media encoder. I tried restarting after update, next is to revert to previous version.

  • Video with Synched Slides used as a Video Component ?

    I would like to take an existing Synched video and slide show .fla file and convert it to a FLV file for insertion onto a page with multiple videos. I was willing to try and convert to QT format and then convert to FLV and drop the video component on

  • Last Year MTD/YTD Column Without Using Time Series Function

    I need to calculate MTD and YTD of last year without using time series function. My requirement is like: We are working on Fiscal year. Suppose user will select a date: 15-Jan-2013

  • More questions about iphone family plan - second line regular phone

    I am planning to switch from a verizon family plan(2 phones) to att family plan with 1 3g iphone and one regular phone. I will get the iphone and my wife won't what is the best free phone to get from att ? and how can i do this in apple retail store?