الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[مخالف - طلب حل : ]الى كل أصحاب الخبرة في الجافا اتمنى الدخول

مغلق
بدأه عطر البنفسج في 23 مارس 2011 · 3 رد · 384 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم انا طالبة مبتائة في الجافا اتمنى تشوفوا شو الخطا في حل

هالاسئلة

1 Problem Specification

Find a suitable algorithm to calculate the parity bit for a given sequence of bits (0's and 1's). We have

two types of parity: even parity and odd parity as explained below.

1.1 Even Parity

Given a sequence of bits you get even parity by adding an additional bit number 1 or 0 such that the

total number of 1's is even as follows.

1001001 -> parity bit = 1

0010100 -> parity bit = 0

1.2 Odd Parity

Given a sequence of bits you get odd parity by adding an additional bit number 1 or 0 such that the

total number of 1's is odd as follows.

1001001 -> parity bit = 0

0010100 -> parity bit = 1

هذا الحل

import java.io.UnsupportedEncodingException;

import static java.lang.System.out;

public final class TestParity

{

// -------------------------- STATIC METHODS --------------------------

private static boolean isOddParity( final byte b )

{

int bb = b;

int bitCount = 0;

for ( int i = 0; i < 8; i++, bb >>>= 1 )

{

if ( ( bb & 1 ) != 0 )

{

bitCount++;

}

}

return ( bitCount & 1 ) != 0;

}

private static boolean isOddParityViaSosman( final byte b )

{

final int bb = b & 0xff;

int parity = bb ^ ( bb >> 4 );

parity ^= parity >> 2;

parity ^= parity >> 1;

return ( parity & 1 ) != 0;

}

public static void main( String[] args ) throws UnsupportedEncodingException

{

out.println( isOddParity( ( byte ) 0xff ) ); // false

out.println( isOddParity( ( byte ) 0x70 ) ); // true

out.println( isOddParityViaSosman( ( byte ) 0xff ) ); // false

out.println( isOddParityViaSosman( ( byte ) 0x70 ) ); // true

}

}

#2

أنا اللي شايفه أن الجواب لا يناسب السؤال

597657.png
#3

تفضلي

import java.lang.*;
import javax.swing.*;
public class ParityBit
{
    private static void CalculateParityBit( String s, String parity)
    {
        if(!parity.toLowerCase().equals("odd") && !parity.toLowerCase().equals("even"))
        {
            JOptionPane.showMessageDialog(null, "You can only choose either Even Parity or Odd Parity!");
            return;
        }
        if(s.trim().length() == 0)
        {
            JOptionPane.showMessageDialog(null, "You didn't enter anything!");
            return;
        }
        char[] cArray = s.trim().toCharArray();
        for(char c : cArray)
        {
            if(!Character.isDigit(c) && c != '1' && c != '0')
            {
                JOptionPane.showMessageDialog(null, "You can only enter 1 or 0");
                return;
            }
        }
        if(cArray.length != 7)
        {
            JOptionPane.showMessageDialog(null, "You must enter only 7-bit binary number!");
            return;
        }
        int bitCount = 0;
        for(int i = 0; i < 7; i++)
        {
            if(!Character.isDigit(cArray) || cArray != '1' || cArray != '0')
            {
                if(cArray == '1') bitCount++;
            }
        }
        int parity_bit = parity.toLowerCase().equals("odd") ? (bitCount + 1) % 2 : bitCount % 2;
        JOptionPane.showMessageDialog(null, parity.toUpperCase() + " PARITY: the parity bit is " + parity_bit);
    }

    public static void main( String[] args )
    {
        String myString = JOptionPane.showInputDialog(null,"Enter a 7-bit binary number:");
        if(myString == null) // Cancel button is pressed!
        {
            JOptionPane.showMessageDialog(null, "Good Bye!");
            return;
        }
        String parity = JOptionPane.showInputDialog(null,"Even Parity or Odd Parity? (Type either 'Even' or 'Odd'):");
        if(parity == null)  // Cancel button is pressed!
        {
            JOptionPane.showMessageDialog(null, "Good Bye!");
            return;
        }
        CalculateParityBit(myString, parity);
    }
}
597657.png
#4

الأخ الكريم/الأخت الكريمة

السلام عليكم ورحمة الله وبركاته.

مرحباً بكم في منتدى الفريق العربي للبرمجة

تأسف إدارة المنتدى لغلق الموضوع وذلك لمخالفته قوانين المشاركات، فقرة طلب حل الواجبات والتمارين.

قواعد طرح المشاركات

/index.php?showtopic=29343

شاكرين لكم حُسن تعاونكم

هذا الموضوع مغلق.

مواضيع مشابهة

عدد الزوار حالياً

المتواجدون خلال آخر دقيقتين · يتحدّث كل ٣٠ ثانية

—الإجمالي—أعضاء مسجّلون—زوار بدون تسجيل

جارٍ التحقق من المتواجدين…